I have this code for a command button when pressed it should add data to the database at the same time update the datagridview and add a new row
private void button1_Click(object sender, EventArgs e)
{
try
{
cn.Open();
cmd.CommandText = "INSERT INTO [Table](Code, Name, Price, units)VALUES('" + codeTextBox.Text + "','" + nameTextBox.Text + "','" + priceTextBox.Text + "','" + unitsTextBox.Text + "')";
cmd.ExecuteNonQuery();
cn.Close();
string col1 = codeTextBox.Text;
string col2 = nameTextBox.Text;
string col3 = priceTextBox.Text;
string col4 = unitsTextBox.Text;
string[] row = { col1, col2, col3, col4 };
tableDataGridView.Rows.Add(row);
tableDataGridView.RowCount++;
}catch(Exception bs)
{
}
the outcome is the data from the textboxes does go to the database and it updates when brought to a new row but the row count doesnt increment any ideas?