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


Please Help Members By Posting Answers For Below Questions

What do you know about ADO.NET's objects and methods?

509


What is a serialized object?

525


Name which operations can you not perform on an ado.net dataset?

475


What is ado connection?

499


Explain how do you connect to sql server database without using sqlclient?

472






Is it possible to load multiple tables in a Dataset?

517


Explain the basic use of "dataview" and explain its methods.

517


What is a column variable?

492


Explain the various objects in dataset.

520


What is disconnected data?

574


What is an ado?

512


What are the key events of sqlconnection class?

598


What is sqldatareader?

480


Give an example of a .net application which connects to microsoft access database using ado.net classes.

575


What is the role of data provider in ado.net?

535