各位好:
我想在某个控件里面输入几个字符串(例如a,b),然后在下表item1字段中查询,返回item1等于a或b的所有行,请问在vb.net2003里面用什么控件和什么方法可以实现??谢谢大家!!
item1 | item2 |
a | 1 |
b | 2 |
c | 3 |
可能表达不是很清晰!
item1 | item2 |
a | 1 |
b | 2 |
c | 3 |
对于以上这个问题,我用了一个textbox和一个listbox实现了,具体代码如下:
‘button1按钮的作用是添加Textbox的数据到Listbox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "" Then
ListBox1.Items.Add(Trim(TextBox1.Text))
TextBox1.Text = ""
Else
MessageBox.Show("请输入电话号码!", MessageBoxButtons.OK)
End If
End Sub
‘button2按钮的作用是查询数据
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ListCount As Integer
ListCount = ListBox1.Items.Count
If ListCount = 0 Then
MessageBox.Show("数据库中没有此电话号码!", MessageBoxButtons.OK)
Else
MessageBox.Show(ListCount)
Dim i As Integer
i = 0
DataSet11.Tables(0).Clear()
Dim a As String
a = SqlDataAdapter1.SelectCommand.CommandText ’定义a的值
Do While ListCount ’循环
SqlDataAdapter1.SelectCommand.CommandText = a
If i = ListCount Then Exit Do
SqlDataAdapter1.SelectCommand.CommandText = SqlDataAdapter1.SelectCommand.CommandText & " where 被叫号码 like " & "'" & ListBox1.Items.Item(i) & "'"
SqlDataAdapter1.Fill(DataSet11.Tables(0))
MessageBox.Show(DataSet11.Tables(0).Rows.Count)
i = i + 1
Loop
End If
End Sub