can you help me to fix this code??
i made that one but there's a problem in searching once you enter the form it just paste all the reservation. but i need to be categorize by name, address, roomtype and email

Imports MySql.Data.MySqlClient

Public Class search
    Public conn As New MySqlConnection
    Dim selected_row, count As String

    Private Sub search_load(ByVal server As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If conn.State = ConnectionState.Closed Then
            conn.ConnectionString = "SERVER = localhost; USERID = root; PASSWORD =; DATABASE = kahuna  "
        End If
    End Sub

    Public Function WithDrawal(ByVal Amount As Decimal, _
      ByVal TransactionCode As Byte) As Double
        ' Add code here to perform the withdrawal,
        ' return a transaction code, 
        ' or to raise an overdraft error.
    End Function

    Public Sub LoadPeople()
        Dim sqlQuery As String = "SELECT * FROM reservation"
        Dim sqlAdapter As New MySqlDataAdapter
        Dim sqlcmd As New MySqlCommand
        Dim TABLE As New DataTable
        Dim i As Integer

        With sqlcmd
            .CommandText = sqlQuery
            .Connection = conn
        End With

        With sqlAdapter
            .SelectCommand = sqlcmd
        End With

        For i = 0 To TABLE.Rows.Count - 1
            With lvresult
                With .Items(.Items.Count - 1).SubItems

                End With
            End With
    End Sub

    '    Private Sub btn_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_search.Click

    'Select Case Me.cmb_search.Text

    'Case "by Name"
    'Me.txb_search.Enabled = True
    'Dim comm_sender As New MySqlCommand("SELECT * FROM Name WHERE `Sender` LIKE '%" & Me.txb_search.Text & "%'", conn)
    'Dim rdr As MySqlDataReader = comm_sender.ExecuteReader
    'Dim number, roomtype, pangalan, lugar, email, contact, guest, room, book, payment, adate, ddate, messsage As String

    'delete the contain documents

    'read command then access data to display
    'While rdr.Read
    'number = rdr.Item("Number")
    'roomtype = rdr.Item("RoomType")
    'pangalan = rdr.Item("Name")
    'lugar = rdr.Item("Location")
    'email = rdr.Item("Email")
    'contact = rdr.Item("Phone")
    'guest = rdr.Item("NoGuest")
    'room = rdr.Item("NoRoom")
    'book = rdr.Item("BookingType")
    'payment = rdr.Item("Payment")
    'adate = rdr.Item("ADate")
    'ddate = rdr.Item("DDate")
    'messsage = rdr.Item("Message")

    'Me.lvresult.rows.Add(number, roomtype, pangalan, lugar, email, contact, guest, room, book, payment, adate, ddate, messsage)

    'count = Me.lvresult.Rows.Count
    '         If count = 0 Then
    '              Me.Label1.Text = "No document/s found."
    '           Else
    '                Me.Label1.Text = count - 1 & " " & "document/s found."
    '             End If
    '          End While

    '   End Select
    'End Sub
End Class

hope somebody can help me

You should have a different SQL clause depending on your search box. Procedure LoadPeople should start like this

Dim sqlQuery As String

Select Case ComboBox1.SelectedValue.ToString()
    Case "Name"
        sqlQuery = "SELECT * FROM reservation ORDER BY Name"
    Case "Room type"
        sqlQuery = "SELECT * FROM reservation GROUP BY RoomType"
End Select

Since you execute this code from the form's load event, you have to fill search combo in there and set a proper combobox index in order to load "default view" (which could be empty too).


This article has been dead for over six months. Start a new discussion instead.