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)
- how to create ASP.NET Core 3 Web API Project - January 21, 2022
- JWT Authentication using OAUTH - January 10, 2022
- Ado.net database Transactions - January 9, 2022