代码如下:
<%@ 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

解决方案 »

  1.   

    LZ试试:adapter.Fill(DR)
    MyDataGrid.DataSource = DR改成:
    adapter.Fill(DR,"mytable")
    MyDataGrid.DataSource = DR.Tables["mytable"]
      

  2.   


    不知道VB语法是不是这样写。
    LZ试试。
      

  3.   

    try:<%@ Import Namespace="System.Data.SqlClient" %>
    <%@ 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&iexcl;&iexcl;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"
    />