代码如下:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ import namespace="System.Data"%><script language="VB" runat="server" Debug="true">
Sub Page_Load(Src As Object, E As EventArgs)
dim DR as DataSet
Dim MyConnection As SQLConnection =New SQLConnection("server=localhost;uid=sa;pwd=123;database=aspnet")Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = new SqlCommand("select * from [User]", MyConnection)
adapter.Fill(DR)
MyDataGrid.DataSource = DR
MyDataGrid.DataBind()
MyConnection.Close()
End Sub
</script>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/> 执行后:报错如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------Value cannot be null.
Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: dataSetSource Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example: <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario. Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: dataSet]
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +224
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +86
ASP.example6_aspx.Page_Load(Object Src, EventArgs E) +115
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ import namespace="System.Data"%><script language="VB" runat="server" Debug="true">
Sub Page_Load(Src As Object, E As EventArgs)
dim DR as DataSet
Dim MyConnection As SQLConnection =New SQLConnection("server=localhost;uid=sa;pwd=123;database=aspnet")Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = new SqlCommand("select * from [User]", MyConnection)
adapter.Fill(DR)
MyDataGrid.DataSource = DR
MyDataGrid.DataBind()
MyConnection.Close()
End Sub
</script>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/> 执行后:报错如下:
Server Error in '/' Application.
--------------------------------------------------------------------------------Value cannot be null.
Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: dataSetSource Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example: <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario. Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: dataSet]
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +224
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +86
ASP.example6_aspx.Page_Load(Object Src, EventArgs E) +115
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
解决方案 »
- 怎样控制Repeater控件显示的行数
- 发送表情时出现问题
- 如何查询数据库中非键字段的不重复数据.
- 最近在看ASP.NET高级编程这本书,有个文件夹里有Componet.cs、Componet.aspx 和makefile文件
- 救急,对象不存在
- shell编程
- 关于登录和AD结合的问题
- 在线等待)关于动态添加控件显示问题?
- 如何在javascript中调用一个外部可执行文件(如:cmd.exe)?
- 在需要认证的EMAIL服务器上发邮件在ASP.NET中如何实现
- 一个页面2个按钮,1个提交有验证,1个提交无验证,怎么把他们分开
- Session_End事件中还能不能取到Session.SessionID了?
MyDataGrid.DataSource = DR改成:
adapter.Fill(DR,"mytable")
MyDataGrid.DataSource = DR.Tables["mytable"]
不知道VB语法是不是这样写。
LZ试试。
<%@ import namespace="System.Data"%><script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
dim DR as DataSet
Dim MyConnection As SQLConnection =New¡¡SQLConnection("server=localhost;uid=sa;pwd=123;database=aspnet")
DR = New DataSet("Customers")Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = new SqlCommand("select * from [User]", MyConnection)
adapter.Fill(DR)
MyDataGrid.DataSource = DR
MyDataGrid.DataBind()
MyConnection.Close()
End Sub
</script>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
/>