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
Related Article: Find text and remove [HOW]
is a VB.NET discussion thread by 432 that has 1 reply and was last updated 1 year ago.
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