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 the difference between Optimistic and Pessimistic locking?
What is difference between ado and other data object?
Why ca not we use multiple inheritance and garbage collector paralelly in .net?
What is a dataview?
Explain which name space is used to get assembly details?
How do you update a dataset in ado.net?
What are the different ado.net namespaces are available in .net?
Which is the feature of ado.net?
What are the different namespaces used in the project to connect the database? What data providers available in .net to connect to database?
How to pass values into a datatable?
How to check if a datareader is closed or opened? IsClosed()
Command objects uses, purposes and their methods.
What are the different row versions available in table?
What is ole db and odbc?
What is the difference in an abstract class and an interface?