Newbie Select Count issue

  • Thread starter Thread starter Jim Campau
  • Start date Start date
J

Jim Campau

Can someone please tell me what is wrong with this code.
I know that the line indicated with and arrow is wrong somehow, but I am not
sure about the query either.
I am just trying to have the txtBox return the number of rows that has [Code
Number] = 2
By the way this is an Access Database

Thanks in advance


Public Sub btnRun_Click(ByVal sender As ystem.Object, ByVal e As
System.EventArgs) Handles btnRun.Click

ChangeOverDataSet1.Clear()
OdbcDataAdapter1.Fill(ChangeOverDataSet1)

Dim Connection As Odbc.OdbcConnection = New dbc.OdbcConnection

Dim Command As Odbc.OdbcCommand = New dbc.OdbcCommand("SELECT COUNT (*)
FROM tblPkgDT_rev2 WHERE [Code Number] = '2'", OdbcConnection1)

---> txtResult.Text = Command.ToString

End Sub
 
That call the ToString method of the OdbcCommand object. I don't know if
this class happens to override this method or not. If not, it will just
return the name of the class.

In any case, you are not actually executing the query in the code you are
showing. You need to open the connection, execute the query, and then close
the connection.
 
Command.ToString will just return the name of the object (in this case
System.Data.Odbc.OdbcCommand). If you want to access the result then execute
the command on an open connection (in your case OdbcConnection1). You can
Execute the command using ExecuteScalar() method on the OdbcCommand.

HTH,
Sushil.
 
Back
Top