Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将dataTable链接到DatagridView_Vb.net - Fatal编程技术网

Vb.net 将dataTable链接到DatagridView

Vb.net 将dataTable链接到DatagridView,vb.net,Vb.net,我正在用DatagridView链接DataTable,但当我想创建新行时,给我一个错误System.NullReferenceException未由用户代码处理。对象引用未设置为对象的实例。 在Result\u btn\u Click()中尝试访问时,tblresult不存在 查看您的页面加载()方法: If IsPostBack Then Exit Sub ' <-- This gets called and the code below won't execute.

我正在用
DatagridView
链接
DataTable
,但当我想创建新行时,给我一个错误
System.NullReferenceException未由用户代码处理。对象引用未设置为对象的实例。



Result\u btn\u Click()
中尝试访问时,
tblresult
不存在

查看您的
页面加载()
方法:

If IsPostBack Then
    Exit Sub ' <-- This gets called and the code below won't execute.
             '     Therefore tblresult doesn't exist in the click handler
End If

If ResultGV.Rows.Count = 0 Then

    tblresult = New DataTable("tblresult")
    ' ...

End If
如果我是回邮的话

Exit Sub“代码中的哪一行引发异常?在drCurrent=tblresult.NewRow()中给出异常请给出解决方案,我能做什么?当然,第二次单击会给出相同的错误
tblresult
仅在第一次加载页面时存在。由于该表是回发的,因此随后对该页的每次调用都不会包含该表。我只能给你上面的提示。由于不知道任何细节,我无法解决你的问题。请熟悉ASP.NET事件模型的工作原理。HTTP是一种无状态协议。在尝试使用ASP.NET WebForms.OK之前,您应该注意以下几点。但是,通过单击事件在dataTable中添加新行并将其绑定到datagridview的理想方法是什么?是否有任何方法可以通过虚拟步骤填充datagridview,以便一次性保存到数据库中?
If IsPostBack Then
    Exit Sub ' <-- This gets called and the code below won't execute.
             '     Therefore tblresult doesn't exist in the click handler
End If

If ResultGV.Rows.Count = 0 Then

    tblresult = New DataTable("tblresult")
    ' ...

End If