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
Which method is used by command class to execute SQL statements that return single value?
Explain how can we load multiple tables in to dataset?
What is data view and variable view?
How to work with disconnected data - the dataset and sqldataadapter?
How do you update a dataset in ado.net and how do you update database through dataset?
What are basic methods of dataadapter?
Difference between sqlcommand and sqlcommandbuilder?
What is dao and ado?
What are the advantages using ado.net?
What is sqlconnection and sqlcommand?
What is ado connection?
Explain the two fundamental objects in ado.net?
What is a dataview?
What is the difference between ado.net and oledb?
What is the difference between SqlCommand and SqlCommandBuilder?