i have been doing insert query but each time it fails
INSERT INTO Mytable (Id, name) VALUES (txtbox1.value, txtbox2.value),
how to use this query using sql connection and pass two paramerters.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ashutosh GuptaPosted Dec 16, 2019, 10:38 AM
Vinitha TPosted Oct 30, 2021, 12:51 PM
private void Insert (int ID , string name){
using (SqlConnection con = new SqlConnection(Your data source ConnectionString))
{
string query = "Insert into table values (@ID, @Name)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.Text;
con.Open();
cmd.Parameters.AddWithValue(@ID, ID);
cmd.Parameters.AddWithValue(@Name,Name);
cmd.ExecuteNonQuery();
}
}
Vincent Maverick DuranoPosted Dec 16, 2019, 10:24 AM