ASP.NET WITH SQL CONNECTION C#
By karthick
, in
ASP.NET WITH SQL CONNECTION C#
,
c#
,
C# cooding for asp.net
,
sql connection in asp.net using c#
,
0 Comments
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();