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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ashutosh GuptaRank #805 · 2.9K reputationPosted Dec 16, 2019, 5:38 AM EST
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Dec 16, 2019, 5:24 AM EST
Vinitha TRank #8,005 · 230 reputationPosted Oct 30, 2021, 8:51 AM EDT
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();
}
}