Heya guys, this is my first post - this forum has been loads of help in the past :)

Anyway, I am currently coding a program that requests a user's Log In name and password, and then (via a SQL query) checks it against a record in the database, and returns the Member Number. The only thing is that I'm not sure how to return the Member Number into a variable. Here's what I have so far:

sqlcon.Open()
Dim username As String = UsernameTextbox.Text
Dim password As String = PasswordTextbox.Text
Dim memnumber as integer
Dim DataCommand As New SqlCeCommand

DataCommand = sqlcon.CreateCommand
DataCommand.CommandText = "SELECT MemberNumber FROM MembersProgramDetails WHERE Username =" & username & "AND Password =" & password
'RETURN VALUE OF MEMBER NUMBER TO (memnumber)

Any help is greatly appreciated,
Ryan.

DataCommand.CommandText = "SELECT MemberNumber FROM MembersProgramDetails WHERE Username='" & username & "' AND Password='" & password & "'"

Thanks adatapost, got it sorted using your help, and the SqlDataReader, here's the code if anyone is interested:

sqlcon.Open() ' globally declared connection
Dim username As String = UsernameTextbox.Text
Dim password As String = PasswordTextbox.Text
Dim memnumber as integer
Dim DataCommand As New SqlCeCommand
 
DataCommand = sqlcon.CreateCommand
DataCommand.CommandText = "SELECT MemberNumber FROM MembersProgramDetails WHERE Username ='" & username & "'AND Password ='" & password & "'"

Dim DataReader as SqlCeDataReader = DataCommand.ExecuteReader()
While DataReader.read
memnumber = (DataReader(0))       ' the 0 means to return the first value of what the data reader has returned
End While
DataReader.close
sqlcon.close
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.