0

I been searching for code but unfortunatelly I failed, So what better way than asking fellow coder. I dont know how to explain but here what I need. I want to be able to search using textbox associated with radio buttons. I can find anything that is related to STRING ut not integer... Here is my code

    Imports MySql.Data.MySqlClient

Public Class frmGuest Dim MysqlConn As MySqlConnection Dim Command As MySqlCommand Dim dbDataSet As New 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

Click here for image

11
  • For idguest just set rowfilter = 'idguest = ' & txtSearch.text Dec 6, 2015 at 12:47
  • Column name idguest is correct? Also make sure it exists in data view Dec 6, 2015 at 13:04
  • It is correct and exist in dataview. As I say, for string it is working such as the name..but not the idguest and NRIC. Do you have email so I can SC??
    – CreedxGin
    Dec 6, 2015 at 13:23
  • Please share some sample data in these columns and data type as well Dec 6, 2015 at 13:37
  • Irfan, I add an image for refrence
    – CreedxGin
    Dec 6, 2015 at 13:52

1 Answer 1

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
5
  • This code work fine for Name and NRIC but not for the idguest
    – CreedxGin
    Dec 6, 2015 at 17:54
  • Actually i have tried for sample data with same column names and it works. now there is some information missing. Can you share some sample data? Dec 6, 2015 at 20:44
  • Try to replace idguest with Convert(idguest,'System.String') OR post a screenshot of table structure Dec 6, 2015 at 20:45
  • Its working now...Thanks alot..Btw Irfan, I'm working on a system now, do you mind if I ask you some question if My code doesnt work??
    – CreedxGin
    Dec 7, 2015 at 9:11
  • Sure. Just post your question i will do my best to asdress it. Dec 7, 2015 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.