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
What is ole db and odbc?
What is difference between executenonquery and executequery?
What are the advantage of ado.net?
What are the important features of ado.net 2.0?
How can we add relation between tables in a dataset?
How can I retrieve two tables of data at a time by using data reader? Data reader read and forward only, how is it possible to get 2 tables of data at a time?
What is ado and dao?
Can datareader hold data from multiple tables?
What does executenonquery () method return?
Which object needs to be closed?
What is different between sqlcommand object and command behavior object?
Explain the two fundamental objects in ado.net?
What is ado.net object model?
What are the different ado.net namespaces?
What is sql connection in ado.net?