There are 10 rows in primary_student_table.
When I execute the following code, the result was -1.
Dim count As Int16
con.Open()
query = "SELECT COUNT(roll) AS rollcount FROM primary_student_table WHERE admityear = 2011 AND batch = 1 "
cmd = New SqlCommand(query, con)
count = cmd.ExecuteNonQuery
MsgBox(count)
con.Close()
What's the problem in the above code?
Disposeoncmdandconafter you've finished using them. 2. Nothing wrong withInt16, but in VB.NET you'd usually refer to that type using the keywordShort. 3. Ideally, you'd callcon.Open()at the latest-possible moment, i.e. right before executing the command; i.e. generally, try to keep connections open for the shortest-possible time.count(*)andcount(row)can produce different results.