C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

Showing posts with label SQl Store Procedure. Show all posts
Showing posts with label SQl Store Procedure. Show all posts

C# : Insert data in sql database using stored Procedure in asp.net

♠ Posted by uvesh in ,

How to insert data in sql server database using asp.net and c#



First of all require to Create database, create connection, and then Following code help full to you



string constring = "Data Source=server name here.;Initial Catalog=DatabaseName;Integrated Security=True";

SqlConnection dbCon = new SqlConnection(constring);

SqlCommand sqlCmd;

DataTable dbTbl;

sqlCmd = new SqlCommand();

dbCon.Open();

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Connection = constring;


sqlCmd.CommandText = ("INSERT INTO TABLE NAME VALUES(jack,newyork,U.S.A) ");

sqlCmd.ExecuteNonQuery()

dbCon.Close();

Example of Above code

string constring = "Data Source=localhost.;Initial Catalog=Shop;Integrated Security=True";

SqlConnection dbCon = new SqlConnection(constring);

SqlCommand sqlCmd;

DataTable dbTbl;

sqlCmd = new SqlCommand();

dbCon.Open();

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Connection = constring;


sqlCmd.CommandText = ("INSERT INTO EMP  VALUES(jack,newyork,U.S.A) ");

sqlCmd.ExecuteNonQuery();

dbCon.Close();


Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/