There are 3 textboxes->textbox1,textbox2,textbox3 and 1 button.
In textbox1 bname will be stored and in textbox2 aname is stored.
Bname and aname are columns of databasetable.
This are not unique.
There are same bnames and anames records.
What I am trying to do is:
when the user clicks on button then the code should match textbox1 and textbox2 with the databasetable and get the count of rows that match this data.
And print the count in the textbox3.
If there is no similar bname and aname in the table then the count should show 0.
I tried doing this but am pretty sure that its not right as its not working.
umm what is the solution?

And you will populate (show) all bnames into textbox1, and all anames into textbox2?
How they will be seperated?
This is not a good idea, better use a listBox, so items will be in a seperated rows.

Why not post your code? It will be easier to identify where you are going wrong...

Create a connection to the database, using this as a reference.

Connect to the database and create/execute a query, storing the values in a table:

Dim ConStr As String = "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"

Dim con As OleDBConnection(ConStr)

Dim cmd As OleDBCommand
Dim da As New OledbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Dim sqls As String = "SELECT aname,bname FROM table WHERE primary_key=value"

Try

    con.Open
    cmd = new OleDBCommand(sqls,con)
    da.SelectCommand = cmd
    da.Fill(ds,"nameTable")
    dt = ds.Tables("nameTable")


    If dt.Rows.Count < 1 Then
        'Table is empty, no names found'
    Else
        'Post names to multiline textboxes or listview.'
        'Listview is easier to use.'
    End If

Catch ex As Exception
    MsgBox(ex.Message)
End Try

The syntax for counting number of records with 2 criteria is :
select count(*) from table where column1 = 'value1' and column2= 'value2'

I'm guessing that you are a beginner and won't get you messed up with parameters, so set up your command like
x = "select count(*) from table where column1 = '" & textbox1.text &"' and column2= '" & textbox2.text & "' "

You haven't told us what database you are using or how you are connecting to it, so x is the command text for whatever you are using.
Since you are only looking for 1 number you don't need to use datatables and can ExecuteScalar to get your value and assign it to textbox3 (textbox3.text = cmd.ExecuteScalar)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.