这段代码给了我在combobox中的system.data.datarowview show.But我想用数据填充组合框。什么是错误?
Dim adclasstecher As New SqlDataAdapter
Dim tbclassteacher As New DataTable
If cnSchool.State = ConnectionState.Closed Then cnSchool.Open()
cmclassteacher.Connection = cnSchool
cmclassteacher.CommandText = "SELECT * FROM Teachers"
cmclassteacher.ExecuteNonQuery()
adclasstecher.SelectCommand = cmclassteacher
adclasstecher.Fill(tbclassteacher)
With cmbclzteachr
.DataSource = tbclassteacher
.DisplayMember = "ClassTeacher"
.SelectedIndex = 0
End With
cnSchool.Close()
答案 0 :(得分:0)
Dim adclasstecher As New SqlDataAdapter
Dim tbclassteacher As New DataTable
If cnSchool.State = ConnectionState.Closed Then cnSchool.Open()
cmclassteacher.Connection = cnSchool
cmclassteacher.CommandText = "SELECT * FROM Teachers"
cmclassteacher.ExecuteNonQuery()
adclasstecher.SelectCommand = cmclassteacher
adclasstecher.Fill(tbclassteacher)
With cmbclzteachr
.DataSource = tbclassteacher
.DisplayMember = "ClassTeacher"
.SelectedIndex = 0
.databind() //you need to bind the data after providing datasource
End With
cnSchool.Close()