ASP.NET WITH SQL CONNECTION C#


HEADER

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


CREATE
SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("CREATE TABLE Persons (PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); ", con1);
      
       cmd.ExecuteNonQuery();

INSERT

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("INSERT INTO Table_1 (id, name)VALUES ('"+TextBox1.Text+"','"+TextBox2.Text +"') ; ", con1);
      
        cmd.ExecuteNonQuery();

SELECT

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
  SqlCommand cmd = new SqlCommand("select * from login ",con1 ); 
        rd1=cmd.ExecuteReader();
        while (rd1.Read())
        {
          TextBox1.Text= rd1.GetString(1).ToString();
                        }


DELETE

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("DELETE FROM Table_1 WHERE id='"+TextBox2.Text +"'; ", con1);
      
        cmd.ExecuteNonQuery();






UPDATE

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("UPDATE Table_1 SET name='"+TextBox2.Text+"' WHERE id='"+TextBox1.Text+"';  ", con1);
      
        cmd.ExecuteNonQuery();

ASP.NET WITH SQL CONNECTION C#


HEADER

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


CREATE
SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("CREATE TABLE Persons (PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); ", con1);
      
       cmd.ExecuteNonQuery();

INSERT

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("INSERT INTO Table_1 (id, name)VALUES ('"+TextBox1.Text+"','"+TextBox2.Text +"') ; ", con1);
      
        cmd.ExecuteNonQuery();

SELECT

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
  SqlCommand cmd = new SqlCommand("select * from login ",con1 ); 
        rd1=cmd.ExecuteReader();
        while (rd1.Read())
        {
          TextBox1.Text= rd1.GetString(1).ToString();
                        }


DELETE

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("DELETE FROM Table_1 WHERE id='"+TextBox2.Text +"'; ", con1);
      
        cmd.ExecuteNonQuery();






UPDATE

SqlConnection con1 = new SqlConnection("Data Source=MCANODE-102\\MCA;Initial Catalog=master;Integrated Security=True");
        SqlDataReader rd1 = null;
        con1.Open();
        SqlCommand cmd = new SqlCommand("UPDATE Table_1 SET name='"+TextBox2.Text+"' WHERE id='"+TextBox1.Text+"';  ", con1);
      
        cmd.ExecuteNonQuery();

Message box for asp.net c#




Alert for asp.net c#

Type cstype = this.GetType();

            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;

            // Check to see if the startup script is already registered.
            if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
            {
                String cstext = "alert('karthi');";
                cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);

            }



Your IP Address is:

Browser: