Results 1 to 3 of 3

Thread: Getting contents of one cell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    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?

  2. #2
    New Member
    Join Date
    Dec 2002
    Posts
    4
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    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
  •  



Click Here to Expand Forum to Full Width