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.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-24 : 07:24:07
|
Brenda writes "I am trying to return a row count so I can display in the application I am building in VB.NET. This is what I have so far: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 is equal to -1. How do I get it to return the actual number of rows so I can display it?" |
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2004-06-24 : 08:04:05
|
You cannot use ExecuteNonQuery() for this task. You can either use ExecuteScalar() to get the value returned by the query. Or do something like:rdr = cmdSqlCommand.ExecuteReader() MessageBox.Show(rdr(0))OS |
 |
|
|
|
|