We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Most efficient way to query a single value from a database?

Hi all,

I've been using this type of code to pull out a single value from my SQL database but I can't help thinking that there's a simple command I'm not using:

strSQL = "SELECT MAX(Stage) FROM Visits WHERE ScheduleRef = 22"
        FinalStage = dl.getPRISMdata(strSQL).Tables(0).Rows(0).Item(0)
Public Function getPRISMdata(ByVal strSQL As String) As DataSet

        Dim conn As New SqlConnection(ConnectionStringPRISM)
        Dim ds As New DataSet

        conn.Open()

        Dim da As New SqlDataAdapter(strSQL, ConnectionStringPRISM)
        da.Fill(ds)
        Return ds


    End Function

It's the tables(0).rows(0).item(0) that bothers me. It works, but should I be doing something different here? Something more efficient in the function perhaps?

Thanks!

2
Contributors
2
Replies
3 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
Paradox 99
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
sufyan2011
Junior Poster
166 posts since Dec 2011
Reputation Points: 9
Solved Threads: 22
Skill Endorsements: 0

ExecuteScaler, see the following link for your solution:

http://funbytebitstop.wordpress.com/2008/04/15/count-records-using-executescalar-in-aspnet/

Perfect! Thank you!

Paradox 99
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by sufyan2011

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3498 seconds using 2.7MB