1,105,416 Community Members

Fetching Data into a Variable

Member Avatar
Rahul47
Posting Whiz
340 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
Rahul47
Posting Whiz
340 posts since Jan 2013
Reputation Points: 13 [?]
Q&As Helped to Solve: 20 [?]
Skill Endorsements: 2 [?]
 
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.

Question Self-Answered as of 1 Year Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article