|
-
Dec 23rd, 2002, 06:40 PM
#1
Thread Starter
Addicted Member
Getting contents of one cell
I have done so simple queries before with asp.net but I always bind all the results to a datagrid.
Is there a way to just get the results of a query into a int?
lets say I used a query like this:
SELECT MAX(Id) FROM Pubs
this should only return a single int, any idea how to just collect that and store it in an int?
-
Dec 23rd, 2002, 07:23 PM
#2
New Member
I use the ADO.NET ExecuteScalar method of the OleDbCommand object like this:
Public Function GetPartnerCount(ByVal strEmail As String) As Integer
Dim nPartnerCount As Integer
Dim conTeeTime As New OleDbConnection (ConfigurationSettings.AppSettings("ConnectionString"))
Dim cmdTeeTime As New OleDbCommand("SELECT COUNT(*) FROM Partners WHERE Player = '" & strEmail & "'", conTeeTime)
Try
conTeeTime.Open()
nPartnerCount = cmdTeeTime.ExecuteScalar
conTeeTime.Close()
Return nPartnerCount
Catch
Return -1
End Try
End Function
This code works against an Access database, but there's a similar object for MS SQL
-
Dec 23rd, 2002, 08:04 PM
#3
Thread Starter
Addicted Member
Awesome.. just what I was looking for.. thanks so much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|