TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
alaa
NA
166
84.9k
populating other columns of gridview based on first column
May 11 2015 5:49 PM
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
Reply
Answers (
0
)
SQL Select Statement
serialization a fileupload