Can someone help me, how to count duplicate rows in vb.net using mysql . auto count after search or filter but in my code it count all existing data within the range

my code:

 Try
            con.Open()
            With cmd
                .Connection = con
                .CommandText = "select s_monthname, count(*) as Total from sample2"
                reader = .ExecuteReader
            End With

            da.SelectCommand = cmd
            table1.Clear()
            da.Fill(table1)
            DataGridView1.DataSource = table1
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            con.Dispose()

        End Try

Please help me

To count record nos. the syntax is

select count(*) from <TableName> Where <Condition>

To get the number of records the syntax is

Dim x as Integer = .ExecuteScalar()
or
Int x =.ExecuteScalar()

A little addition to Shark_1's post,

You probably will also want to add a Group By onto that select statement. So for instance if you want to see how many occurances there are of the s_monthname in the table, but only return distinct records in relation to the month name (so only 1 record) you could do something like

select s_monthname, count(*) as Total from sample2 GROUP BY s_monthname

Not only will that return the s_monthname value, but the Total will be how many times that a value in that column has occured in the table (but all in one record)

commented: yeah yeah.. all in one record will display.. so this is the right syntax? gonna try this one +0

Thank you guys, it really works.. i ask again later

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.