The following code, is supposed to add a new record to the table 'Lista'. The code runs without any problems, but does not reflect in the table. The table contains 3 columns, Id (Is Identity is set to true), Color (nvarchar(50)) and Tela (nvarchar(50)).
I have tried and tried to figure this out, but no luck. I have also set the App.config File property, 'Copy to Output Directory' to 'Copy if Newer'. Please, help!
private void SaveLista()
{
String ConString = ConfigurationManager.ConnectionStrings["WindowsFormsApp33.Properties.Settings.Testbase1ConnectionString"].ConnectionString;
SqlConnection connection;
String query = "INSERT INTO Lista ([Color], [Tela]) VALUES (@Color, @Tela)";
using (connection = new SqlConnection(ConString))
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
command.Parameters.AddWithValue("@Color", txtColor.Text);
command.Parameters.AddWithValue("@Tela", txtTela.Text);
int i = Convert.ToInt32(command.ExecuteScalar());
MessageBox.Show(i.ToString());
}
}
The result should be a new record in the table containing the values for Color and Tela which are in the TextBoxes on the form. The Id, of course, is filled automatically. Instead, the table remains empty! Thanks for any help!