Dim conn As new ADODB.Connection

解决方案 »

  1.   

    未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 34:         Dim conn As New ADODB.Connection()
    行 35:         Dim com As New ADODB.Command()
    行 36:         conn.Open("driver={SQL Server};server=shanle;uid=sa;pwd=sa;database=OaExpand")
    行 37:         conn.Close()
      

  2.   

    参考:private void Bind()
    {
       OleDbDataAdapter custDA = new OleDbDataAdapter();
       DataTable dtTerritories = new DataTable("Territories");
       
       ADODB.Connection adoConn = new ADODB.Connection();
       ADODB.Recordset adoRS = new ADODB.Recordset();
       
       adoConn.Open("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;User Id=;Password=;", "", "", -1);
       adoRS.Open("SELECT TerritoryID, TerritoryDescription FROM Territories Order By TerritoryDescription", adoConn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1);
       
       custDA.Fill(dtTerritories, adoRS);
       
       adoRS.Close();
       adoConn.Close();
       
       adoRS = null;
       adoConn = null;
       
       DataGrid1.DataSource = dtTerritories;
       DataGrid1.DataBind();
       
       DropDownList1.DataSource = dtTerritories;
       DropDownList1.DataValueField = "TerritoryID";
       DropDownList1.DataTextField = "TerritoryDescription";
       DropDownList1.DataBind();
    }
      

  3.   

    你只是定义,都没new !当然是末将对象引用设置到对象实例的啦!
      

  4.   

    ^_^,你没有new呀,对于对象是需要new的,当然处理string,integer等除外
      

  5.   

    Dim strConn As String = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=jnjl;Data Source=shanle"
            Dim objConn As New SqlClient.SqlConnection(strConn)
            Dim strSql As String = "SELECT user_id, user_name, user_pwd, dept_id, user_order FROM dbo.[user]"
            Dim objCmd As New SqlClient.SqlCommand(strSql, objConn)
            dgNameList.DataSource = objCmd.ExecuteReader()
            dgNameList.DataBind()
            objConn.Close()我这样写还是错误,不明白、了,说的是Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=jnjl;Data Source=shanle"这个有错误
    “/jnjl”应用程序中的服务器错误。
    --------------------------------------------------------------------------------连接字符串 provider 中未知的连接选项。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentException: 连接字符串 provider 中未知的连接选项。源错误: 
    行 42:     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    行 43:         Dim strConn As String = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=jnjl;Data Source=shanle"
    行 44:         Dim objConn As New SqlClient.SqlConnection(strConn)
    行 45:         Dim strSql As String = "SELECT user_id, user_name, user_pwd, dept_id, user_order FROM dbo.[user]"
    行 46:         Dim objCmd As New SqlClient.SqlCommand(strSql, objConn)
     源文件: C:\Inetpub\wwwroot\jnjl\login.aspx.vb    行: 44 堆栈跟踪: 
      

  6.   

    下面的总是new了把,一样的出错了,迷惑
      

  7.   

    Dim rs As ADODB.Recordset
            Dim conn As New ADODB.Connection()
            Dim com As New ADODB.Command()
            'Dim sql As String
            conn.Open("Provider=SQLOLEDB;driver={SQL Server};server=shanle;uid=sa;pwd=sa;database=jnjl")
            com.ActiveConnection = conn
            'sql = "SELECT user_id, user_name, user_pwd, dept_id, user_order FROM dbo.[user]"
            com.CommandText = "SELECT user_id, user_name, user_pwd, dept_id, user_order FROM dbo.[user]"
            com.CommandType = 1
            rs = com.Execute()
            While Not rs.EOF
                Dim aa
                aa = rs("user_name")
                ListBox1.Items.Add("11")
                'ListBox1.Items.Add(rs("user_name"))
                rs.MoveNext()
            End While
            'DataList1.DataSource = rs
            'DataList1.DataBind()
            conn.Close()就差一点点了,这样是正常的,但是加上这个'ListBox1.Items.Add(rs("user_name"))
    就不能了,好像数据不对,我不明白,谁能给详细解释一下我的问题,分不够在开帖子给