尊敬的先生,
VB 2008.我试图通过Textbox.Text搜索数据集表作为变量。但它给出了错误,我在这段代码中做了任何错误吗?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim myID = TextBox1.Text
Dim myArray() As DataRow
Dim i As Integer
myArray = myDataSet.myTable.Select("PRODUCTID" = myID)
For i = 0 To (myArray.Length - 1)
ListBox1.Items.Add(myArray(i)("PRODUCTID").ToString)
Next
End Sub
你的忠实
Murulimadhav
答案 0 :(得分:1)
您需要将select命令视为SQL Select的WHERE部分。你的代码应该是这样的:
myArray = myDataSet.myTable.Select("PRODUCTID = " & myID)
这假设您在该表中有一个名为PRODUCTID的字段,它是数字。如果是文本/字符串,则需要用引号括起来:
myArray = myDataSet.myTable.Select("PRODUCTID = '" & myID & "'")