Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

In how many ways we can retrieve table records count? How to find the count of records in a dataset?

1009


What is the return type of executescalar?

1017


Which object needs to be closed?

2260


Do we use stored procedure in ADO.Net?

992


What is difference between Dataview and Datatable?

1067


What are the Features of a dataset

1307


What is oledb connection?

988


Why ca not we use multiple inheritance and garbage collector paralelly in .net?

1005


What is ado or jdbc?

924


Which ado.net object is very fast in getting data from the database?

1105


What are the namespaces used in ADO.Net to connect to a database?

1212


What is csdl entity framework?

1022


What is the full form of ado?

1012


What is sql command in ado net?

958


What is the difference between ado.net and oledb?

952