Click here to Skip to main content
16,018,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a mysql table which i have imported into a datatable as below

mysqlconn.Open()
strquerry = "select * from site_details order by monitorname;"
sqlcmd = New MySqlCommand(strquerry, mysqlconn)
dadapter = New MySqlDataAdapter(sqlcmd)
dadapter.Fill(dt)


The above code is working fine.
Now I have a textbox in which when user enters a string and clicks on search, it should look into the above datatable and search it in all columns. It should collect the rows and then display the data on a dynamically created table.

i have already tried using
datatable.select()
function but to no use.

Any advice is greatly appreciated. Thanks
Posted
Comments
Peter Leow 2-Dec-13 10:50am    
Your code is too sketchy. What do you want users to enter in the search textbox? monitorname?
Davesh Borasi 3-Dec-13 4:24am    
Any details present in the table. If available it should display the data other wise display messege that data is not available
Glagace_7763 2-Jan-14 16:53pm    
Here is a good start you would have to add checks for nulls and integers etc.

1 solution

Public Class Form1

    Dim returntable As DataTable = New DataTable("returnTable")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sSearchtext As String = "HP"

        Dim table As DataTable = New DataTable("table")

        Dim colItem As DataColumn = New DataColumn("col1", Type.GetType("System.String"))
        table.Columns.Add(colItem)
        Dim colItem1 As DataColumn = New DataColumn("col2", Type.GetType("System.String"))
        table.Columns.Add(colItem1)


        Dim NewRow As DataRow
        NewRow = table.NewRow()
        NewRow("col1") = "HP"
        NewRow("col2") = "Dell"
        table.Rows.Add(NewRow)

        Dim NewRow2 As DataRow
        NewRow2 = table.NewRow()
        NewRow2("col1") = "ViewSonic"
        NewRow2("col2") = "Generic"
        table.Rows.Add(NewRow2)

        table.AcceptChanges()

        'clone the table schema
        returntable = table.Clone

        For Each row As DataRow In table.Rows
            For Each col As DataColumn In table.Columns
                'compare each column value
                If String.Compare(row(col).ToString(), sSearchtext, True) = 0 Then
                    'if match then load value
                    LoadData(row)
                    'exit now no need to continue to search the rest of the columns
                    Exit For
                End If
            Next

        Next

        MsgBox(returntable.Rows.Count.ToString)

    End Sub

    Private Sub LoadData(ByRef rRow As DataRow)

        Try
            '
            returntable.ImportRow(rRow)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900