我一直在寻找代码但不幸的是我失败了,所以还有什么比问同事更好的方式。我不知道如何解释,但在这里我需要什么。我希望能够使用与单选按钮关联的文本框进行搜索。我可以找到任何与STRING相关的内容而不是整数... 这是我的代码
Imports MySql.Data.MySqlClient
Public Class frmGuest 昏暗的MysqlConn作为MySqlConnection Dim命令为MySqlCommand Dim dbDataSet作为新DataTable Dim row As DataGridViewRow
Private Sub guestLoad()
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString =
"server=localhost;userid=admin;password=admin;database=gdatabases"
Dim SDA As New MySqlDataAdapter
Dim bsource As New BindingSource
Try
MysqlConn.Open()
Dim Query As String
Query = "select * from gdatabases.guest"
Command = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = Command
SDA.Fill(dbDataSet)
bsource.DataSource = dbDataSet
DataGridView1.DataSource = bsource
SDA.Update(dbDataSet)
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
Private Sub frmGuest_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
guestLoad()
End Sub
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim DV As New DataView(dbDataSet)
If rdoReg.Checked Then
DV.RowFilter = String.Format("idguest like = {0}", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoName.Checked Then
DV.RowFilter = String.Format("Name like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoNRIC.Checked Then
DV.RowFilter = String.Format("Convert(NRIC,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
End If
End Sub
答案 0 :(得分:0)
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim DV As New DataView(dbDataSet.Tables(0))
If rdoReg.Checked Then
DV.RowFilter = String.Format("idguest = {0}", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoName.Checked Then
DV.RowFilter = String.Format("Convert(Name,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
ElseIf rdoNRIC.Checked Then
DV.RowFilter = String.Format("Convert(NRIC,'System.String') Like '%{0}%'", txtSearch.Text)
DataGridView1.DataSource = DV
End If
End Sub