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

my code:

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

            da.SelectCommand = cmd
            DataGridView1.DataSource = table1
        Catch ex As MySqlException

        End Try

Please help me

Recommended Answers

All 3 Replies

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()
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.