I am trying to insert an integer value into a SQL Server database as below when I run the program there are no any errors, but the table doesn't get updated with values. I have searched on the internet and I am doing the same can anyone help to find what I am doing wrong.
Note: I already defined "connectionString" as a string on the form class
private void btnUpdate_Click(object sender, EventArgs e)
{
int totalincome=600;
int totaldeductions = 10;
connectionString = ConfigurationManager.ConnectionStrings["BudgetApp.Properties.Settings.MainDataBaseConnectionString"].ConnectionString;
con = new SqlConnection(connectionString);
con.Open();
cmd = new SqlCommand("INSERT INTO Totals(TotalIncome, TotalDeductions) VALUES (@TotalIncome, @TotalDeductions)", con);
cmd.Parameters.AddWithValue("@TotalIncome", totalincome);
cmd.Parameters.AddWithValue("@TotalDeductions", totaldeductions);
cmd.ExecuteNonQuery();
MessageBox.Show("Done !!");
}
Done !!at the end of execution?TransactionScopein play?cmd.ExecuteNonQuery();returns the number of rows affected. If it's greater than zero, it worked. If the database doens't show it, you are looking in the wrong database.