基本上,如果组合框选择(字段)是“engineering”,那么只会显示与该选择相对应的行。我想访问下一行数据,这些数据与此(字段)选择相似且仅对应,并适当地填充文本框控件。将显示该行中该组合框选择下保存的所有数据。这个很好用。按钮1下的代码模块是我试图访问下一行的代码,但显示的数据不正确。是否有修复和显示所需数据的方法-组合框选择符合数据库条件的下一整行sql数据。
Private Sub BtnSearch_Click(sender As Object, e As EventArgs) Handles BtnSearch.Click
Dim Command As New SqlCommand("Select * From Table_Upload where Field = @Field", Connection)
Dim DA As New SqlDataAdapter(Command)
Dim DT As New DataTable()
Dim DR As SqlDataReader
Command.Parameters.Add("@Field", SqlDbType.VarChar).Value = CmbField.SelectedItem
DA.Fill(DT)
CmbField.DataSource = DT
CmbField.DisplayMember = "Field"
Connection.Open()
DR = Command.ExecuteReader()
If DR.Read() Then
TxtTitle.Text = DR(0)
TxtComp.Text = DR(1)
TxtDate.Text = DR(2)
TxtSalary.Text = DR(3)
CmbEmp.SelectedItem = DR(4)
TxtDesc.Text = DR(5)
TxtExp.Text = DR(6)
TxtPhone.Text = DR(7)
TxtEmail.Text = DR(8)
TxtAddr.Text = DR(9)
End If
Connection.Close()
End Sub
下一步代码:private sub button1\u click(sender as object,e as eventargs)处理btnnext。click dim command as new sqlcommand(“select*from table\u upload where field=@field”,connection)dim da as new sqldataadapter(command)dim ds as new dataset()dim dr as sqldatareader
Command.Parameters.Add("@Field", SqlDbType.VarChar).Value = CmbField.SelectedItem
DA.Fill(DS, "Table_Upload")
CmbField.DisplayMember = "Field"
Connection.Open()
DR = Command.ExecuteReader()
If DR.Read() Then
TxtTitle.Text = DR(+1).ToString()
TxtComp.Text = DR(+1).ToString()
TxtDate.Text = DR(+1).ToString()
TxtSalary.Text = DR(+1).ToString()
CmbEmp.SelectedItem = DR(+1).ToString()
TxtDesc.Text = DR(+1).ToString()
TxtExp.Text = DR(+1).ToString()
TxtPhone.Text = DR(+1).ToString()
TxtEmail.Text = DR(+1).ToString()
TxtAddr.Text = DR(+1).ToString()
End If
Connection.Close()
末端接头
2条答案
按热度按时间dnph8jn41#
一旦有了数据读取器,就创建一个
DataTable
并称之为Load
方法加载所有数据。然后可以绑定DataTable
到BindingSource
以及BindingSource
给你的TextBoxes
. 你可以打电话给我MoveNext
通过数据前进。编辑:
在根据joelcoehoorn下面的评论进行了一些阅读和测试之后,我了解到,虽然不能将数据读取器直接绑定到windows窗体中的控件,但可以将数据读取器绑定到
BindingSource
它会产生一个IBindingList(Of DataRecordInternal)
,这是一个IList
从而满足winforms绑定的要求。一DataRecordInternal
可以按列名或序号索引,方法与DataRow
或者DataRowView
可以,因此它们可以以几乎相同的方式进行处理。不管怎样
kuhbmx9i2#
“我想访问下一行数据”
打个电话就可以了
DR.Read()
再一次。