I have a problem, I want to add an item using datareader in the datagridview which is I can only add once and if I add another one it'll error. Here's my codes:
connect = new OleDbConnection(coo); connect.Open();
command.Connection = connect;
DataTable dt = new DataTable();
OleDbDataAdapter ODA = new OleDbDataAdapter("SELECT * FROM Items where itemno = '" + textBox1.Text + "'", connect);
ODA.Fill(dt);
command.CommandText = "SELECT * FROM Items";
OleDbDataReader reader = command.ExecuteReader();
object[] obj = new object[256];
while (reader.Read())
{
reader.GetValues(obj);
if ((textBox1.Text == obj[0].ToString()))
{
if (dataGridView1.DataSource == null)
dataGridView1.DataSource = dt;
else
((DataTable)dataGridView1.DataSource).Merge(dt);
int sum1 = 0;
for (int i = 0; i < dataGridView1.RowCount; i++)
{
sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
}
textBox2.Text = sum1.ToString();
break;
}
else if (textBox1.Text==null)
{
break;
}
}
reader.Close();
connect.Close();
The error appeared as "Input string was not in a correct format" at the sum1 += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);... All I want is the items that I want to add at the datagridview have their prices and will add it all in the datagridview which is the total is in the textbox. plz help me guys..
Aucun commentaire:
Enregistrer un commentaire