populating other columns of gridview based on first column
hello everybody how can Auto populating other columns of the gridview based on the value in the first column
i try this code but it gets error
private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
int count = dataGridView1.Columns.Count;
if (e.RowIndex >= 0)
{
if (!string.IsNullOrEmpty(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()))
{
id1 = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());
populateColumns();
dataGridView1.Rows[e.RowIndex].Cells[4].Value = barcode;
dataGridView1.Rows[e.RowIndex].Cells[5].Value = price;
dataGridView1.Rows[e.RowIndex].Cells[6].Value = unit;
}
}
}
private void populateColumns()
{OleDbConnection conConnect = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Application.StartupPath + "\\Store.mdb");
{
string str = "SELECT Product.ID, Units.Unit, Product.barcode, Product.price FROM Units INNER JOIN Product ON Units.Un_id = Product.Un_id WHERE proname " +
id1 + "';";
OleDbCommand cmd =
new OleDbCommand(str, conConnect);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet("dsEmployee");
da.Fill(ds);
conConnect.Open();
foreach (DataRow row in ds.Tables[0].Rows)
{
try
{
barcode = row["barcode"].ToString();
price = row["price"].ToString();
unit = row["Unit"].ToString();
}
catch (FormatException fEx)
{
MessageBox.Show(fEx.Message);
}
}
}
}
the error is Object reference not set to an instance of an object.null referance unhandle how it can be done