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
In how many ways we can retrieve table records count? How to find the count of records in a dataset?
What is the return type of executescalar?
Which object needs to be closed?
Do we use stored procedure in ADO.Net?
What is difference between Dataview and Datatable?
What are the Features of a dataset
What is oledb connection?
Why ca not we use multiple inheritance and garbage collector paralelly in .net?
What is ado or jdbc?
Which ado.net object is very fast in getting data from the database?
What are the namespaces used in ADO.Net to connect to a database?
What is csdl entity framework?
What is the full form of ado?
What is sql command in ado net?
What is the difference between ado.net and oledb?