Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 COUNT number of records...help!

Author  Topic 

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-06-21 : 10:28:20
CountRecords = "SELECT COUNT (CaseNumber) FROM tblHUDdata"
Dim SqlConn4 As SqlConnection = New SqlConnection("data source=localhost;initial catalog=crdatabase;integrated security=SSPI;persist security info=False;workstation id=CRSERVER;packet size=4096")
Dim cmdSqlCommand4 As SqlCommand = New SqlCommand(CountRecords, SqlConn4)
cmdSqlCommand4.Connection.Open()
Try
Dim Answer As String
answer = cmdSqlCommand4.ExecuteNonQuery()
MessageBox.Show(" & answer & " Records Were Imported.")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
SqlConn4.Close()

The variable "answer" always outputs a -1. Why won't it give how many records are in the table? How do I display that answer in my VB application? Please HELP!

gpl
Posting Yak Master

195 Posts

Posted - 2004-06-21 : 11:10:11
As I understand it, this is a 'feature' - see this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=36332
Go to Top of Page

Maux Maux
Starting Member

10 Posts

Posted - 2004-06-22 : 09:15:33
Try using executescalar instead of executenonquery. You are executing a sql statement that is supposed to return a value. executenonquery assumes that you are not getting a return.
Go to Top of Page

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-06-22 : 15:38:15
The ExecuteScalar thing worked perfectly. It was so easy. Thanks!
Go to Top of Page
   

- Advertisement -