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

Fetching Data into a Variable

hello people, I have the following piece of code.

Private Sub SR_No()
        Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\VB Applications\PROJECT_1\PROJECT_1\examdb.mdf;Integrated Security=True;User Instance=True")
        Dim cmd As New SqlCommand("Select MAX(SR_No) from Stud_Master", con)

        con.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        MessageBox.Show(sr)
        con.Close()
    End Sub

I wish to fetch SR_No into a variable sr.
Advices are welcome.

Thanks

1
Contributor
1
Reply
6 Minutes
Discussion Span
4 Months Ago
Last Updated
2
Views
Question
Answered
Rahul47
Junior Poster in Training
66 posts since Jan 2013
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0

Above Problem is solved as follows.

Private Sub SR_No()
        Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\VB Applications\PROJECT_1\PROJECT_1\examdb.mdf;Integrated Security=True;User Instance=True")
        Dim cmd As New SqlCommand("Select MAX(SR_No) from Stud_Master", con)

        con.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
        dr.Read()
        sr = dr.GetValue(0)
        MessageBox.Show(sr)
        con.Close()
    End Sub

Thanks.

Rahul47
Junior Poster in Training
66 posts since Jan 2013
Reputation Points: 0
Solved Threads: 1
Skill Endorsements: 0
Question Self-Answered as of 4 Months Ago

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

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0593 seconds using 2.71MB