[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Retrieve values from a sql statement

Posted on 2006-05-02
2
Medium Priority
?
214 Views
Last Modified: 2010-04-23
How can it get the values in the select statement and assign them to variables?   Thank you

Dim program, boxnum, dtmdestroydate
                Dim cmdins As New SqlClient.SqlCommand("select program, boxnum, dtmdestroydate from tblrecordsmanagment where lngPatientid = '" & lngpatientid & "'", Connection1)
                Try
                    program = cmdins.ExecuteScalar(0).ToString
                    boxnum = cmdins.ExecuteScalar(1).ToString
                    dtmdestroydate = cmdins.ExecuteScalar(2).ToString
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
0
Comment
Question by:running32
2 Comments
 
LVL 5

Accepted Solution

by:
razorback041 earned 2000 total points
ID: 16588061
try this instead

Dim sqlReader As SqlDataReader = cmdins.ExecuteReader
                Connection1.Open()

                While sqlReader.Read
                    program = sqlReader("program")
                    boxnum= sqlReader("boxnum")
                    dtmdestroydate = sqlReader("dtmdestroydate")
                end while
                Connection1.,close()

0
 
LVL 3

Expert Comment

by:maidinhtai
ID: 16588418
Because the select statement return 1 row or 0 row. So that here is my code:
                Dim cmdins As New SqlClient.SqlCommand("select program, boxnum, dtmdestroydate from tblrecordsmanagment where lngPatientid = '" & lngpatientid & "'", Connection1)
                If Connection1.State = ConnectionState.Closed then Connection1.Open()
                Dim sqlReader As SqlClient.SqlDataReader = cmdins.ExecuteReader()
                If sqlReader.Read then
                    program = sqlReader("program")
                    boxnum= sqlReader("boxnum")
                    dtmdestroydate = sqlReader("dtmdestroydate")
                End If
                sqlreader.Close()
                Connection1.close()
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question