While working with ADO.NET you need to understand the thing why SqlCommand is used.
We have two kind of operations related to database:
1 That will make changes in the database
2 That will not make any change to the database
SqlCommand is used for the first one when we have insert update or delete operation to perform in the database.
For this we always have to open the connection to make changes to the database.
And after finishing work connection should be closed.
SqlConnection conObj=new SqlConnection("");
SqlCommand cmdInsert = new SqlCommand("INSERT INTO client(name,surname) values(@name,@surname)", conObj);
cmdInsert.Parameters.AddWithValue("@name", name.Text);
cmdInsert.Parameters.AddWithValue("@surname", surname.Text);
conObj.Open();
cmdInsert.ExecuteNonQuery();
0 Comment(s)