C# linq数据类中的空引用对象
我在mysql“Customers”中创建了一个表,并创建了一个devart linq connect模型 当我想使用C# linq数据类中的空引用对象,c#,asp.net,mysql,linq,C#,Asp.net,Mysql,Linq,我在mysql“Customers”中创建了一个表,并创建了一个devart linq connect模型 当我想使用linq检索第一行时,它会给出一个null引用异常 (对象引用未设置为对象的实例。) 我的代码是: protected void Page_Load(object sender, EventArgs e) { using (ShoppingDataContext data = new ShoppingDataContext()) {
linq
检索第一行时,它会给出一个null引用异常
(对象引用未设置为对象的实例。)
我的代码是:
protected void Page_Load(object sender, EventArgs e)
{
using (ShoppingDataContext data = new ShoppingDataContext())
{
Customer Mycustomer = data.Customers.First();
Labelshow.Text = Mycustomer.CustomerLastname;
}
}
代码中抛出的异常具体在哪里?在“using”行上,或在调用First()时,或在label赋值中?您刚才看到变量数据是否有值吗?@DavidW异常在Labelshow.Text=mycustomer处引发。CustomerLastname@MayogaX:它有值,我现在在调试模式下看到了。@VishalTorne您是说Mycustomer本身不是空的,或者CustomerLastname有一个值?