Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logon script using executescalar

Status
Not open for further replies.

paulhudson

Programmer
Jan 20, 2005
8
GB
I have a logon page which has three textboxes. On clicking submit the following procedure is called.

Needless to say it fails. Essentially I am trying to count a number of records that match username
password etc from within an access database. If the count is one then the logon is a success.


The problem occurs here:

Count = Convert.ToInt32(oCommand.ExecuteScalar())

With the following error message "Data type mismatch in criteria expression"

Here is the code:


sub Submit(obj as Object, e as EventArgs)
Dim RedirectPage As String
If tbTeam.text = "Club" then
RedirectPage = "ClubAdmin.aspx"
Else
RedirectPage = "TeamAdmin.aspx"
End If

Dim sSQL = "select count(*) from tbusers where username='" & tbUsername.text & "' AND password='" & tbPassword.text & "' AND TeamType='" & tbTeam.text & "';"

Dim oConnect As New OleDbConnection(ConfigurationSettings.AppSettings("connString"))

Dim oCommand As New OleDbCommand(sSQL, oConnect)

Dim Count As Int32

Count = "0"

oConnect.Open()

Count = Convert.ToInt32(oCommand.ExecuteScalar())

oConnect.Close()

Dim LoginCount As Label

LoginCount.Text = Count.ToString()

If LoginCount.Text = "1" Then
Session("Authorized") = "yes"
Session("TeamType") = tbTeam.Text
Session("Username") = tbUsername.Text
Else
lblmessage.text = "Please verify your login information."
End If
End Sub
 
Rather than doing:
Code:
Count = Convert.ToInt32(oCommand.ExecuteScalar())
I would open a DataReader and read the value within that reader. e.g.
Code:
        Dim MyReader As Odbc.OdbcDataReader = odbcCommand.ExecuteReader
        While MyReader.Read
            Count = MyReader.GetInt32(0)
        End While


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top