以下代码中 DpUName 是一个DropDownList,在Init 事件中编写代码,绑定数据表.
以下测试过,绝对可以.
Private Sub DpUName_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DpUName.Init
dim ConStr as String ’’与数据库连接的语句.
ConStr="data source=计算机名(或IP);initial catalog=数据库名;persist security info=False;user id=sa;"
dim SqlStr as String=’Select * from UserInfo’
dim Da As new SqlDataAdapter(Sqlstr,constr)
dim Ds As New DataSet
dim MyTable as New DataTable
Da.Fill(Ds,"UserInfo")
MyTable=Ds.Table(0)
If Mytable.Rows.Count <> 0 Then
DpUName.DataSource = Mytable ’’’绑定数据表
DpUName.DataTextField = "器件名称" ’’’绑定某一字段
DpUName.DataBind()
End If
End Sub
以下测试过,绝对可以.
Private Sub DpUName_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DpUName.Init
dim ConStr as String ’’与数据库连接的语句.
ConStr="data source=计算机名(或IP);initial catalog=数据库名;persist security info=False;user id=sa;"
dim SqlStr as String=’Select * from UserInfo’
dim Da As new SqlDataAdapter(Sqlstr,constr)
dim Ds As New DataSet
dim MyTable as New DataTable
Da.Fill(Ds,"UserInfo")
MyTable=Ds.Table(0)
If Mytable.Rows.Count <> 0 Then
DpUName.DataSource = Mytable ’’’绑定数据表
DpUName.DataTextField = "器件名称" ’’’绑定某一字段
DpUName.DataBind()
End If
End Sub