Updated : Jan 09, 2022 in Articles

system.data.sqlclient class

Sql connection:

it is used to connect to sql server datatabase

sqlconnection con=new sqlconnction("your database connction string here")

Sql command:

it is used to excute an sql command are store processor

sql command cmd=new sqlcommand("sql command,storeprocedure,con")

Establish the connetion to database:

string cs="Server=[server_name];Database=[database_name];Trusted_Connection=true"; 
using(SqlConnection conn = new SqlConnection(cs))
{
   sqlcommand cmd=new sqlcommand("select *from emplyee",con)
   con.open();
   gridview.Datasource=cmd.ExecuteReder;
   Gridview.DataBind();
   con.close();
}

here conncetion should be closed in the finally block or by default using will use the automatically close the connction  ​

Latest posts by DuttaluruVijayakumar (see all)
Like
Like Love Haha Wow Sad Angry

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x