当我尝试创建另一个搜索顺序时,程序卡住了。我的意思是我可以进行一次搜索操作,但随后程序停止工作。
这是我的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static m As Integer = 0
If TextBox1.Text = Trim("") Then Exit Sub
If RadioButton4.Checked = True Then
ExactSearch()
ElseIf RadioButton5.Checked = True Then
GeneralSearch()
End If
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
DataAdapter1.Fill(DataSet1, "Table1")
Conn.Close()
TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Name")
TextBox3.DataBindings.Add("Text", DataSet1, "Table1.DatTim")
TextBox4.DataBindings.Add("Text", DataSet1, "Table1.mobile")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "Table1"
'Button1.Enabled = False
If Me.BindingContext(DataSet1, "Table1").Count = 0 Then
MsgBox("No Result, Please Try Again ")
Exit Sub
End If
Button2.Enabled = True
Button3.Enabled = True
End Sub
Public Sub ExactSearch()
If RadioButton1.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE name = '" & TextBox1.Text & "'"
ElseIf RadioButton2.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE DatTim = '" & TextBox1.Text & "'"
ElseIf RadioButton3.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE mobile = '" & TextBox1.Text & "'"
End If
End Sub
Public Sub GeneralSearch()
If RadioButton1.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE name LIKE '%" & TextBox1.Text & "%'"
ElseIf RadioButton2.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE DatTim LIKE '%" & TextBox1.Text & "%'"
ElseIf RadioButton3.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE mobile LIKE '%" & TextBox1.Text & "%'"
End If
End Sub
它卡在这里
TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Name")
请帮忙。