Database Search

met0555

New member
Joined
Aug 29, 2006
Messages
4
Programming Experience
1-3
well i want to make a search box that will search from the data from the database. i try it so many time but i wasn't able to do it can someone help me. i attached my project please make the code there then upload me tanks


Databse = msft acces
Project = visual basic 2005

please i have a project to do please post it as soon as possible.

tanks
 

Attachments

  • serialtesttosend.zip
    151.7 KB · Views: 20
c'mon, i just checked that project and there's nothing in it. Did you forget to include all the code you have written so far? you dont expect someone here to do it all for you, do you? What you are asking is well documented all over the net and on these forums..

http://www.vbdotnetforums.com/showthread.php?t=12869

Give yourself a chance and have a go. Then post back if you have any specific problems.
 
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim adoConn As New OleDb.OleDbConnection(connStr)
        Dim adoCom As New OleDb.OleDbCommand
        Dim dTable As New DataTable
        Dim dAdapter As New OleDb.OleDbDataAdapter(adoCom)

        AddHandler adoConn.StateChange, AddressOf ado_msg
        adoConn.Open()

        With adoCom
            .Connection = adoConn
            .CommandText = "SELECT * FROM pcserials WHERE ID=" & TextBox1.Text
            .CommandTimeout = 5
            .CommandType = CommandType.Text
        End With

        dAdapter.Fill(dTable)

        DataGridView1.DataSource = dTable

    End Sub

    Sub ado_msg(ByVal sender As Object, ByVal e As System.Data.StateChangeEventArgs)
        'MsgBox(e.CurrentState)
    End Sub

Make sure you add a DataGridView in your form. Also this appears to be a database full of serial keys. I sure hope so it is for your own use. Remove your dataAdapter and your SerialsDataSet and pcserialsDataAdapter objects.

The above code works only when you specify the ID which is your unique key. So for example in your search box just type a number e.g 1. Work it by yourself to enhance your search options.

Also it would be better to use a dataReader instead but I will leave that to you for either to learn or in case you want to update stuff in your database stick with the dataTable.

I prefer to work with hard-written code.
 
to make your search more flexible try to use the "like" keyword instead of using equal(=) sign...
something like this:

"SELECT * FROM pcserials WHERE ID like '" & TextBox1.Text & "%'",connection)
 
Back
Top