大家帮我看看问题到底出在哪里?
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
Dim strConnString As String = "Data Source=ALICK;Initial Catalog=NewBridge;User Id=sa;Password=;" 
        Dim ds As DataSet
        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlDataAdapter
        Dim DropDownList3 As DropDownListMyConnection = New SqlConnection("Data Source=ALICK;Initial Catalog=NewBridge;User Id=sa;Password=;")
MyCommand = New SqlDataAdapter("select * from NB_user", MyConnection)
ds = new DataSet()
MyCommand.Fill(ds,"NB_user")
        DropDownList3.DataSource = ds.Tables("NB_user").DefaultView
        DropDownList3.DataTextField="user_truename"
        DropDownList3.DataValueField="user_truename"
        DropDownList3.DataBind()
End Sub
</script><BODY>
  <form runat="server">
<asp:DropDownList id="DropDownList3" runat="server" />  </form></body>
</html>

解决方案 »

  1.   

    将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 31:  MyCommand.Fill(ds,"NB_user")
    行 32: 
    行 33:  DropDownList3.DataSource = ds.Tables("NB_user").DefaultView
    行 34:         DropDownList3.DataTextField="user_truename"
    行 35:         DropDownList3.DataValueField="user_truename"
     源文件: E:\s2\xq\mail_send.aspx    行: 33 
      

  2.   

    我帮你改改吧:
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <html>
    <script language="VB" runat="server">
    Sub Page_Load(Source As Object, E As EventArgs)
    Dim conn as New SqlConnection("Server=Localhost;uid=sa;pwd=;DataBase=database;")
    Dim ds as new DataSet()
    Dim comm as New SqlDataAdapter("select * from NB_user",conn)
    comm.Fill(ds,"dsName")
    DropDownList3.DataSource = ds.Tables("dsName").DefaultView
    DropDownList3.DataTextField="user_truename"'必须保证此处的user_truename是数据库表中的字段名
    DropDownList3.DataValueField="user_truename"
    DropDownList3.DataBind()
    End Sub
    </script><BODY>
      <form runat="server">
    <asp:DropDownList id="DropDownList3" runat="server" /> 
    </form>
    </body>
    </html>
      

  3.   

    算我愚昧.....
    ConnectString里面的Initial Catalog=NewBridge;是什么意思?等价于DataBase么?Data Source等价于Server么?这个实在看不懂....
    还有,我一般绑定DropDownList用DataReader就好了,很少用DataSet,所以不清楚这个有问题没有
      

  4.   

    楼主这样做就失去了用asp.net的意义。
    最好不要像在asp中一样了。
    如果我刚才写的代码由问题
    发消息给我。
      

  5.   

    你的数据库都没打开怎么读数据。
    --------
    把Connection的Open()打开。
      

  6.   

    楼上的,Fill方法不需要手动打开关闭数据库连接.....