•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 456,530 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,868 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 3814 | Replies: 2
![]() |
•
•
Join Date: Jul 2005
Posts: 19
Reputation:
Rep Power: 4
Solved Threads: 0
Hi
I am trying to get to grips with querying an access database and displaying the information. I have started with a coun sql command to just return the number of rows but wanted to display this to the screen but each time it shows as null - there are records in my db so either my sql is wrong or a msgbox will not retrieve the data as perhaps the data is already lost by the time I try calling the msgbox?
My code is:
I then try and display it using:
But it always shows as nothing!
I am sure I am missing something obvious(well to everyone else but not me!).
Can anyone help...?
Maybe it is easier to display in a list?
Thanks....
I am trying to get to grips with querying an access database and displaying the information. I have started with a coun sql command to just return the number of rows but wanted to display this to the screen but each time it shows as null - there are records in my db so either my sql is wrong or a msgbox will not retrieve the data as perhaps the data is already lost by the time I try calling the msgbox?
My code is:
Function TotalOutOfSpec()
Dim conn = New Odbc.OdbcConnection
' connectionstring using session variable ConnString to connect to user's database
conn.ConnectionString = Session.Item("ConnString")
Dim sql = "SELECT count (*) FROM TestResults WHERE OutofSpec = 'True'"
Dim command As New Odbc.OdbcCommand(sql, conn)
Dim returnValue As Odbc.OdbcDataReader
Try
'Open the connection
conn.Open()
returnValue = command.ExecuteScalar
TotalOutOfSpec = returnValue
'close and dispose of the connection to the database
conn.close()
conn.dispose()
command.Dispose()
returnValue.Close()
Catch ex As Exception
End Try
End FunctionI then try and display it using:
MsgBox("Record count: " & OutOfSpec)But it always shows as nothing!
I am sure I am missing something obvious(well to everyone else but not me!).
Can anyone help...?
Maybe it is easier to display in a list?
Thanks....
•
•
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation:
Rep Power: 7
Solved Threads: 59
the ExecuteScalar method returns an object (in VB.NET in VB6 I can't remember perhaps a variant) not a reader. The object is the value in the first column of the first row of the odbc result set.
Also your code doesn't look like valid VB.NET to me. Don't you have to declare the return type of the function? it's looking like VB6 or VBA syntax to me, especially with the brackets missing from the end of ExecuteScalar. Are you in the right forum?
Also your code doesn't look like valid VB.NET to me. Don't you have to declare the return type of the function? it's looking like VB6 or VBA syntax to me, especially with the brackets missing from the end of ExecuteScalar. Are you in the right forum?
Last edited by hollystyles : Oct 9th, 2007 at 10:02 am.
•
•
Join Date: Jul 2005
Posts: 19
Reputation:
Rep Power: 4
Solved Threads: 0
Thanks for the reply. I am using VB.net but just messing up my syntax I'm afraid!
I was using executescalar() was initially I was doing a Count, so point taken for my revised sql statement I should change this to ExecuteReader()
I will continue looking at this, but thanks for he response
I was using executescalar() was initially I was doing a Count, so point taken for my revised sql statement I should change this to ExecuteReader()
I will continue looking at this, but thanks for he response
Last edited by JavaFish : Oct 9th, 2007 at 10:38 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- pagination and search (PHP)
- putting result of a sql query in a file in shell scripting (Shell Scripting)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
- Warning: mysql_num_rows(): (PHP)
- display punctuations in word count hash map (Java)
- SQL search query (PHP)
- Help with a reservation program! GUI Messed XD (Java)
Other Threads in the VB.NET Forum
- Previous Thread: Closing form
- Next Thread: Set the starting form



Linear Mode