VB连接数据库后如何使combox控件下拉菜单显示,但是没有显示
DimmysqlAsString="SELECTlingjiangmingFROMlingjiankucun"DimmyconnstrAsString="server=....
Dim mysql As String = "SELECT lingjiangming FROM lingjiankucun"
Dim myconnstr As String = "server=.; Integrated Security=False;Initial Catalog= pro; User ID= sa;PWD=204112"
Dim myconn As SqlConnection = New SqlConnection(myconnstr)
Dim mycomm As SqlCommand = New SqlClient.SqlCommand(mysql, myconn)
myconn.Open()
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter(mycomm)
da.Fill(ds, "lingjiankucun")
ComboBox1.DataSource = ds.Tables("lingjiankucun")
ComboBox1.DisplayMember = ("lingjiangming") 展开
Dim myconnstr As String = "server=.; Integrated Security=False;Initial Catalog= pro; User ID= sa;PWD=204112"
Dim myconn As SqlConnection = New SqlConnection(myconnstr)
Dim mycomm As SqlCommand = New SqlClient.SqlCommand(mysql, myconn)
myconn.Open()
Dim ds As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter(mycomm)
da.Fill(ds, "lingjiankucun")
ComboBox1.DataSource = ds.Tables("lingjiankucun")
ComboBox1.DisplayMember = ("lingjiangming") 展开
1个回答
展开全部
Dim StrSql As String
Dim StrConn As String
Dim Cnn As SqlConnection '数据库对象
Dim Cmd As SqlCommand '记录集对象
Dim Dr As SqlDataReader '数据操作对象
Dim ds As New DataSet
StrConn = "server = (local);Initial Catalog=pro;User ID=sa;Password=204112;"
StrSql = "select * from lingjiankucun"
Dim cmd As New SqlCommand(strSql, cn)
Cnn = New SqlConnection(StrConn)
Cmd = New SqlClient.SqlCommand(StrSql, Cnn)
Cnn.Open()
Da = Cmd.ExecuteReader()
While Da.Read
ComboBox1.Items.Add(Da("需要放置的字段名"))
End While
'已经测试,字段数据已经加载到 ComboBox1 控件中了,但我的 StrConn 与 StrSql 字符串与你的不一样。
我的数据库是SQL 2008 数据库
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询