i want 2 pass values(enterd in textbox)to table in sql
server without using stored procedure in c#.plz tell me
code with an example.

Answer Posted / sandeep singh shekhawat

Solution1:
SqlConnection con=new SqlConnection("Data Source=./SqlExpress;Database=Test;Integrated Security= true;")
SqlDataAdapter adp=new SqlDataAdapter("insert into employee values(@Id,@Name)",con);
dap.SelectCommand.Parameters.AddwithValue("@Id",TextBox1.Text);
dap.SelectCommand.Parameters.AddWithValue("@Name",TextBox2.Text);

for this sql Connection define globally and after that all code write on button click event.


Solution2
SqlConnection con=new SqlConnection("Data Source=./SqlExpress;Database=Test;Integrated Security= true;")
SqlCommand cmd=new SqlCommand("insert into emp values(@Id,@Name)",con)
cmd.Parameter.AddWithValue("@Id",TextBox1.Text);
cmd.Parameter.AddwithValue("@Name",TextBox2.Text);
if(con.State==ConnectionState.Closed)
con.Open();
cmd.ExecuteNonQuery();

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the core objects of ADO.NET?

782


What are the parameters that control most of connection pooling behaviours?

808


Explain the architecture of ado.net?

797


What is ado code?

700


Explain the two fundamental objects in ado.net?

673


What is disconnected scenario in entity framework?

765


What do you know about ado.net's methods?

790


Can we load multiple tables in a dataset?

786


What is ado and dao?

712


What is difference between executenonquery and executequery?

688


What is the default timeout specified for "sqlcommand.commandtimeout" property?

751


What is difference between dataset and datatable?

756


describe the dataset object in ado.net.

706


What is fill method in ado.net?

716


Which database is the ado.net sql connection object designed for?

807