注册 登录
编程论坛 ASP.NET技术论坛

未将对象引用设置到对象的实例 急!!!!!!急!!!请各位大虾求救呀

twtdd 发布于 2008-06-17 16:47, 779 次点击
出错: DropDownList1.DataSource = objds.Tables(" DropDownList1").DefaultView



Imports System.Data
Imports System.Data.oledb
Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents RadioButton12 As System.Web.UI.WebControls.RadioButton
    Protected WithEvents pagemode2 As System.Web.UI.WebControls.RadioButton
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region
    Dim objconn As OleDbConnection
    Dim objcmd As OleDbDataAdapter
    Dim objds As DataSet
    Dim strsql, strdsn As String


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            strsql = "select distinct 作者 from 书籍1"
            strdsn = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("mydb.mdb")
            objconn = New OleDbConnection(strdsn)
            objcmd = New OleDbDataAdapter
            objcmd.TableMappings.Add("table", " DropDownList1")
            objcmd.SelectCommand = New OleDbCommand(strsql, objconn)
            objds = New DataSet(" DropDownList1")
            objcmd.Fill(objds)
            DropDownList1.DataSource = objds.Tables(" DropDownList1").DefaultView
            DropDownList1.DataBind()

           
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strau As String
        strdsn = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("mydb.mdb")
        objconn = New OleDbConnection(strdsn)
        strau = Trim(DropDownList1.SelectedItem.Text)
        strsql = "select * from 书籍1 where 作者= '" & strau & " '"
        objcmd = New OleDbDataAdapter
        objcmd.TableMappings.Add("table", "book2")
        objcmd.SelectCommand = New OleDbCommand(strsql, objconn)
        objds = New DataSet("book2")
        objcmd.Fill(objds)
        DataGrid1.DataSource = objds.Tables("book2").DefaultView
        DataGrid1.DataBind()

    End Sub
  
End Class

[[it] 本帖最后由 twtdd 于 2008-6-17 16:49 编辑 [/it]]
3 回复
#2
twtdd2008-06-17 16:50
请问那里出错了....小弟不胜感激
#3
冰彩虹2008-06-17 20:31
你objds里面有表名为DropDownList1 的表嘛?你自己跟踪看看呀
#4
twtdd2008-06-18 16:10
谢谢了
1