I have created winform project and bound MS Access database to it, I have created dataGridView which its dataSource is from MS Acess database.
I also have created 3 textboxes as to carry data inputs and created "add button" to save textboxes values into MS Access database and show these data in the dataGridView.
This is the "add button" code:
> private void button1_Click(object sender, EventArgs e)
> {
> string firstName = textBox1.Text;
> string secondName = textBox2.Text;
> int age =Convert.ToInt32(textBox3.Text);
> int ID = 0;
> ID += 1;
>
> theDatabase1DataSet.Table1.Rows.Add(ID, firstName,
> secondName, age);
> textBox1.Text = "";
> textBox2.Text = "";
> textBox3.Text = "";
> MessageBox.Show("Inputs have been saved");
> }
I have created winform project and bound MS Access database to it, I have created dataGridView which its dataSource is from MS Acess database.
![enter image description here][2]
I also have created 3 textboxes as to carry data inputs and created "add button" to save textboxes values into MS Access database and show these data in the dataGridView.
This is the "add button" code:
private void button1_Click(object sender, EventArgs e)
{
string firstName = textBox1.Text;
string secondName = textBox2.Text;
int age =Convert.ToInt32(textBox3.Text);
int ID = 0;
ID += 1;
theDatabase1DataSet.Table1.Rows.Add(ID, firstName,
secondName, age);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
MessageBox.Show("Inputs have been saved");
}
When I enter text in the textboxes and click on "add button"
This error message appears " System.ArgumentException: 'Input string was not in a correct format.Couldn't store in age Column. Expected type is Int32.'"