如何从一个列表框中编码选定值以将数据加载到新列表框中。我目前得到一个“没有映射存在从对象类型System.Data.DataRowView到已知的托管提供程序... [英] How do I code for a selected value from one list box to load data into a new list box. I currently get a "No mapping exists from object type System.Data.DataRowView to a known managed provider...
本文介绍了如何从一个列表框中编码选定值以将数据加载到新列表框中。我目前得到一个“没有映射存在从对象类型System.Data.DataRowView到已知的托管提供程序...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
''这是第一个列表框的代码
''Here is the code for the first list box
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myconnection.Open()
'MessageBox.Show("Connection Opened")
Dim mycommand As New SqlCommand
Dim Ins As String = Login.LgnText.Text
Dim section As String = CourseSel.SelectionScreen.Item(1, CourseSel.SelectionScreen.CurrentRow.Index).Value()
mycommand.Connection = myconnection
mycommand.CommandType = CommandType.StoredProcedure
mycommand.CommandText = "StudentGroups"
mycommand.Parameters.AddWithValue("Course", CourseSel.Course.SelectedValue)
mycommand.Parameters.AddWithValue("Ins", Ins)
mycommand.Parameters.AddWithValue("sec", section)
'MessageBox.Show("SQL Statement Executed")
Dim adap As New SqlDataAdapter(mycommand)
Dim dt As New DataTable
adap.Fill(dt)
TeamList.DataSource = dt
TeamList.DisplayMember = "TeamNumber"
TeamList.ValueMember = "TeamNumber"
TeamList.SelectedIndex = -1
myconnection.Close()
End Sub
End Class
''这是我要生成的列表框的代码名称成员
''Here is the code for the list box that I want to generate Names of members
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TeamList.SelectedIndexChanged
'MessageBox.Show("Connection Opened")
Dim mycommand As New SqlCommand
Dim Ins As String = Login.LgnText.Text
Dim section As String = CourseSel.SelectionScreen.Item(1, CourseSel.SelectionScreen.CurrentRow.Index).Value()
mycommand.Connection = myconnection
mycommand.CommandType = CommandType.StoredProcedure
mycommand.CommandText = "TeamMembers"
mycommand.Parameters.AddWithValue("Course", CourseSel.Course.SelectedValue)
mycommand.Parameters.AddWithValue("Ins", Ins)
mycommand.Parameters.AddWithValue("sec", section)
mycommand.Parameters.AddWithValue("TN", TeamList.SelectedValue)
'MessageBox.Show("SQL Statement Executed")
Dim adap1 As New SqlDataAdapter(mycommand)
Dim dt As New DataTable
Dim ds As New DataSet
adap1.Fill(dt)
dt = ds.Tables("TeamNumber")
TeamList.DataSource = dt
TeamList.DisplayMember = "LastName, First Name"
TeamList.ValueMember = "LastName"
TeamList.SelectedIndex = -1
End Sub
推荐答案
这篇关于如何从一个列表框中编码选定值以将数据加载到新列表框中。我目前得到一个“没有映射存在从对象类型System.Data.DataRowView到已知的托管提供程序...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文