Reputation: 1
I'm trying to copy the data from sql table "checkin " to auto fill in on a form in a textbox .. on a button click
DataSet ds = null;
private void button8_Click(object sender, EventArgs e)
{
tblNamesBS.DataSource = ds.Tables[0];
textBox2.DataBindings.Add(new Binding("Text", tblNamesBS,"GuestName"));
}
Upvotes: 0
Views: 143
Reputation: 1232
Like the other guys said you need to instantiate ds before you can use it.
DataSet ds = new DataSet();
Upvotes: 0
Reputation: 998
You cant use ds
before setting it to an object....
Therefore, this call is invalid ds.Tables[0];
-> You are trying to acces Tables from ds, when ds is null
Upvotes: 2
Reputation: 1062975
ds
starts off as null
, and you show no code that would make ds
anything other than null
. Thus indeed, ds.Tables[0]
will explode with a NullReferenceException
.
Make ds
something non-null
.
Upvotes: 3