vb.net 将数据库中的内容显示到comboBox中,加不进去 5
DimstrConnectAsString="server=(local);InitialCatalog=pro;UserID=sa;Password=204112;"D...
Dim strConnect As String = "server = (local);Initial Catalog=pro;User ID=sa;Password=204112;"
Dim strSql As String = "select * from lingjiankucun"
Dim ds As New DataSet
Dim da As SqlDataAdapter
Dim sqlCustomer As String = "select * from lingjiankucun"
Try
Dim cn As New SqlConnection(strConnect)
cn.Open()
Dim cmd As New SqlCommand(strSql, cn)
da = New SqlDataAdapter(cmd)
da.Fill(ds, "lingjiankucun")
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(ds.Tables(0).Rows(i).Item("lingjiangming"))
Next
Catch ex As Exception
MsgBox(ex.GetType.ToString & ":" & ex.Message)
End Try
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 strSql As String = "select * from lingjiankucun"
Dim ds As New DataSet
Dim da As SqlDataAdapter
Dim sqlCustomer As String = "select * from lingjiankucun"
Try
Dim cn As New SqlConnection(strConnect)
cn.Open()
Dim cmd As New SqlCommand(strSql, cn)
da = New SqlDataAdapter(cmd)
da.Fill(ds, "lingjiankucun")
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(ds.Tables(0).Rows(i).Item("lingjiangming"))
Next
Catch ex As Exception
MsgBox(ex.GetType.ToString & ":" & ex.Message)
End Try
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") 展开
3个回答
2018-12-14
展开全部
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 数据库。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询