Monday, October 1, 2018

Insert query in C#

   string query = "INSERT INTO  History (Name,Code,) VALUES (@HName,@HCode, )"
                using (SqlCommand command = new SqlCommand(query, con))
                {  
                    command.Parameters.AddWithValue("@HName", txtAccount.Text);
                    command.Parameters.AddWithValue("@HCode", txtAccount.EditValue);
 
                    con.Open();
                    int result = command.ExecuteNonQuery();

                    // Check Error
                    if (result < 0)
                        MessageBox.Show("Error");
                  
                    con.Close();
                   }

No comments:

Post a Comment