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 do you know about ADO.NET's objects and methods?
What is a serialized object?
Name which operations can you not perform on an ado.net dataset?
What is ado connection?
Explain how do you connect to sql server database without using sqlclient?
Is it possible to load multiple tables in a Dataset?
Explain the basic use of "dataview" and explain its methods.
What is a column variable?
Explain the various objects in dataset.
What is disconnected data?
What is an ado?
What are the key events of sqlconnection class?
What is sqldatareader?
Give an example of a .net application which connects to microsoft access database using ado.net classes.
What is the role of data provider in ado.net?