hi I dont know coding to Insert data in sql with the help of C# language and I want to save data with the click event of save button
how to insert data in sql with C#
Collapse
X
-
Tags: None
-
-
Hey jaydeep1991 take this code as example and change it as per your need. But my suggestion is read the article on the link 'r035198x' posted.
Code:void Save_Click(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection("Your Database Connection String"); SqlCommand cmd = new SqlCommand("Insert into Table_1 (Name) values (@Name)", con); cmd.Parameters.AddWithValue("@Name", "Yourname"); cmd.ExecuteNonQuery(); Console.WriteLine("New row successfully inserted"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { con.Close(); } }Comment
Comment