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
我正在尝试将数据从sql表“checkin”复制到文本框中的表单上自动填充..单击按钮
DataSet ds = null;
private void button8_Click(object sender, EventArgs e)
{
tblNamesBS.DataSource = ds.Tables[0];
textBox2.DataBindings.Add(new Binding("Text", tblNamesBS,"GuestName"));
}
3 个解决方案
#1
3
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
.
ds从null开始,并且您不会显示任何使ds不是null的代码。因此,ds.Tables [0]确实会爆发NullReferenceException。
Make ds
something non-null
.
使ds非空。
#2
2
You cant use ds
before setting it to an object....
在将其设置为对象之前,您无法使用ds ....
Therefore, this call is invalid ds.Tables[0];
-> You are trying to acces Tables from ds, when ds is null
因此,此调用无效ds.Tables [0]; - >当ds为null时,您正尝试从ds访问表
#3
0
Like the other guys said you need to instantiate ds before you can use it.
像其他人一样,你需要先实例化ds才能使用它。
DataSet ds = new DataSet();
#1
3
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
.
ds从null开始,并且您不会显示任何使ds不是null的代码。因此,ds.Tables [0]确实会爆发NullReferenceException。
Make ds
something non-null
.
使ds非空。
#2
2
You cant use ds
before setting it to an object....
在将其设置为对象之前,您无法使用ds ....
Therefore, this call is invalid ds.Tables[0];
-> You are trying to acces Tables from ds, when ds is null
因此,此调用无效ds.Tables [0]; - >当ds为null时,您正尝试从ds访问表
#3
0
Like the other guys said you need to instantiate ds before you can use it.
像其他人一样,你需要先实例化ds才能使用它。
DataSet ds = new DataSet();