Re: How to read values from a datatable?
Quote:
Originally Posted by gggram2013
Well basically I don't know how to code it so as to display the value on a label instead of a comboBox. eg:
Code:
da.Fill(dt);
comboBox.DataSource = dt;
comboBox.DisplayMember = "InvPlusOne";
comboBox.ValueMember = "InvPlusOne";
I would want to put:
Code:
label.DataSource = dt;
label.DisplayMember = "InvPlusOne";
label.ValueMember = "InvPlusOne";
But that does not function since label doesn't have those properties.
Nevertheless, I'm gonna use a comboBox and try hiding it meanwhile, so thanks for ur assistance!
it is not always the case that you have to use databinding (using DataSource) when assigning values from database to a control. if you just want to display a value (scalar), you could assign it to the text/value property of the control. in your case...
Code:
label.Text = dt[0][0].ToString();
How to read values from a datatable?
Hey it works Great now. Thanks for ur help Thread1, it was really helpful.
I put:
Code:
label.Text = dt.Rows[0]["InvPlusOne"].ToString();
Appreciate everyone's help!
George