R
RSH
I am struggling a bit with trying to access data values from a dataset.
What am I doing wrong here???
Thanks,
RSH
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
if(e.RowIndex >= 0)
{
SqlConnection oCon = new SqlConnection("server='ENGINE'; Integrated
Security='SSPI'; database='20039999'");
DataSet ds = new DataSet();
oCon.Open();
SqlDataAdapter oCmd = new SqlDataAdapter("select ID,FirstName,LastName from
Employee WHERE ID = " + dataGridView1.Rows[e.RowIndex].Cells[1].Value ,
oCon);
oCmd.Fill(ds, "Employee");
for (int i = 0; i <= ds.Tables["Employee"].Rows.Count; i++)
{
for (int j = 0; j <= ds.Tables["Employee"].Columns.Count; j++)
{
label1.Text = label1.Text + " " + ds.Tables["Employee"].Rows[j].ToString
+ "\n"; <-------- ERRORS HERE
}
}
oCon.Close();
}
}
What am I doing wrong here???
Thanks,
RSH
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
if(e.RowIndex >= 0)
{
SqlConnection oCon = new SqlConnection("server='ENGINE'; Integrated
Security='SSPI'; database='20039999'");
DataSet ds = new DataSet();
oCon.Open();
SqlDataAdapter oCmd = new SqlDataAdapter("select ID,FirstName,LastName from
Employee WHERE ID = " + dataGridView1.Rows[e.RowIndex].Cells[1].Value ,
oCon);
oCmd.Fill(ds, "Employee");
for (int i = 0; i <= ds.Tables["Employee"].Rows.Count; i++)
{
for (int j = 0; j <= ds.Tables["Employee"].Columns.Count; j++)
{
label1.Text = label1.Text + " " + ds.Tables["Employee"].Rows[j].ToString
+ "\n"; <-------- ERRORS HERE
}
}
oCon.Close();
}
}