|
-
Dec 15th, 2003, 03:48 PM
#1
Thread Starter
New Member
How do I turn the results of an SQL query into Strings and Integers?
Hi guys,
This was easy enough to do in java....
String UserType == NameOfQuery.getString(X);
Although I know how to use a DataReader in VB code for my ASP.NET website to check to see if a record exists, I would really like to be able to use a DataSet so that I can convert a returned field from a record into a String or an Integer which can then be used in my page.
When a user is successfully logged into my website, I'd like the program to be able to look in the tblUsers table and if a field name called 'UserType' contains the String value 'Administrator' to then enable extra features to be available.
I know how to do the latter, but it's how I can give a String variable the returned 'UserType' that I'm unsure of!!!
Could someone please give me a hand with this !!
Thanks,
Si
-
Dec 16th, 2003, 12:35 AM
#2
PowerPoster
Look at the SQLCommand object and you will want to call the ExecuteScalar (spelling may be off). It returns a single value, and you can cast it or whatever.
-
Dec 16th, 2003, 08:02 AM
#3
Thread Starter
New Member
Thanks for the help, but I don't follow....
What does ExecuteScalar mean?
This is my code so far....
Sub SeeIfUserExists()
Dim ConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;data source=" & _
server.mappath("database/BikeBits.mdb")
Dim strSQL as String = ("SELECT * from tblUsers where CustomerCode = '" & txtboxCustomerCode.Text & "' and Password = '" & txtboxPassword.Text &"'")
Dim objConnection as New OledbConnection(ConnectionString)
Dim objCommand as New OleDbCommand(strSQL, objConnection)
Dim objDataReader as OleDbDataReader
try
objConnection.open
objDataReader = objCommand.ExecuteReader()
if objDataReader.Read()=True Then
'do this if record found
Session("Username") = txtboxCustomerCode.Text
Session("LoggedIn") = "Yes"
Response.redirect("mainmenu.aspx")
else
'record doesn't exist, so do this....
objDataReader.Close()
objConnection.Close()
lblError.Text="User not found!"
end if
objDataReader.Close()
objConnection.Close()
catch e as Exception
' con_open.text="Connection failed to open"
' con_close.text=e.ToString
end try
End Sub
Last edited by HELLO.JPG; Dec 16th, 2003 at 04:16 PM.
-
Dec 18th, 2003, 09:52 AM
#4
Hyperactive Member
I am new to ASP.net so don't lame if I'm wrong...
I have been working with vb.net and vb6 for about few years now, and as far as I am aware, VB treats strings and integers the same, you do not need to change them into each other, like in other languages such as Java or C++
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|