Solved

Login Button - Not working

Posted on 2013-06-11
11
279 Views
Last Modified: 2013-06-17
Can anyone tell me where I am going wrong with my login button?


Protected Sub txtLoginBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles txtLoginBtn.Click
        Dim usersadapter As New usersdataset.tbl_otuserstableadapter()
        Dim tbl_otusers As UsersDataSet.tbl_otusersDatatable

        Try
            Dim strUserId As String = txtUserId.Text
            Dim strpwd As String = txtPwd.Text

            Dim numrecords As Int16 = tBL_OTUSERSTableAdapter.FillbyLogin(Me.usersdataset.tbl_otusers, strUserId, strpwd)
            If (numrecords > 0) Then
                Dim dbuserid As String = Me.UsersDataset.tbl_otusers(0).username
                Dim dbpwd As String = Me.usersdataset.tbl_otusers(0).password
                If dbuserid.Equals(strUserId) And dbpwd.Equals(strpwd) Then
                    'user is authenticated
                    Dim mainfrm As New Monthly_OTExc70
                    mainfrm.userid = dbuserid
                    mainfrm.show()
                    Me.close()
                    Return

                Else
                    messagebox.show("Incorrect userid and password. Please try again!")
                    Return
                End If
                messagebox.show("Incorrect userid and password. Please try again!")
            End If


        Catch ex As Exception
            messagebox.show(ex.Message)
            Return
        End Try
    End Sub
0
Comment
Question by:ernie_shah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
11 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39238201
Whats the error?
0
 

Author Comment

by:ernie_shah
ID: 39238587
The code is not being built successfully.

The following lines are underlined...

Dim usersadapter As New usersdataset.tbl_otuserstableadapter()
Dim tbl_otusers As UsersDataSet.tbl_otusersDatatable
Dim dbuserid As String = Me.UsersDataset.tbl_otusers(0).username
Dim dbpwd As String = Me.usersdataset.tbl_otusers(0).password
Dim mainfrm
mainfrm.userid = dbuserid
mainfrm.show()
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39238792
Do you have a typed dataset named UsersDataset in your project?

I would change your code to following (Change SQLConnection and SQLCommand to equivalent oracle objects)

Protected Sub txtLoginBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles txtLoginBtn.Click
        Try
           Dim dbcon as New SqlConnection("your connection string")
           dbcon.Open
           Dim dbcmd as New SqlCommand
           dbcmd.Connection = dbcon
           dbcmd.CommandText = "Select IsNull(Count(*), 0) From Users Where Username=@Username AND Password=@Password"
           dbcmd.Parameters.AddWithValue("@Username", strUserId)
           dbcmd.Parameters.AddWithValue("@Password", txtPwd.Text)
           Dim Count As Integer = dbcmd.ExecuteScalar()
           dbcmd.Dispose
           dbcon.Dispose
           If (Count > 0) Then
                    'user is authenticated
                    Dim mainfrm As New Monthly_OTExc70
                    mainfrm.userid = dbuserid
                    mainfrm.show()
                    Me.close()             
            Else
                    messagebox.show("Incorrect userid and password. Please try again!")
                    Return
            End If
                messagebox.show("Incorrect userid and password. Please try again!")
            End If
        Catch ex As Exception
            messagebox.show(ex.Message)
            Return
        End Try
    End Sub

Open in new window

0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

Author Comment

by:ernie_shah
ID: 39239080
The following runs without any build error but when I click on the button the attached error is thrown.


Protected Sub txtLoginBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles txtLoginBtn.Click
        Try
            Dim dbcon As New SqlConnection("Data Source=mydb;Persist Security Info=True;User ID=myuserid;Password=mypwd")
            dbcon.Open()
            Dim strUserId As String = txtUserId.Text
            Dim strpwd As String = txtPwd.Text
            Dim dbcmd As New SqlCommand
            dbcmd.Connection = dbcon
            dbcmd.CommandText = "Select IsNull(Count(*), 0) From Users Where Username=@Username AND Password=@Password"
            dbcmd.Parameters.AddWithValue("@Username", strUserId)
            dbcmd.Parameters.AddWithValue("@Password", txtPwd.Text)
            Dim Count As Integer = dbcmd.ExecuteScalar()
            dbcmd.Dispose()
            dbcon.Dispose()
            If (Count > 0) Then
                Response.Redirect("~monthly.aspx")
            Else
                MsgBox("Incorrect userid and password. Please try again!")
                Return
            End If
            'MsgBox("Incorrect userid and password. Please try again!")

        Catch ex As Exception
            MsgBox(ex.Message)
            Return
        End Try

    End Sub
error.docx
0
 

Author Comment

by:ernie_shah
ID: 39239117
What  test can I perform to open a connection and read data from an oracle table?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39239385
Yes the issue is with your connection string. Do you have SQL tool that comes with Oracle?

This would be useful as well

http://www.connectionstrings.com/oracle
0
 

Author Comment

by:ernie_shah
ID: 39241077
I don't have any sql tools. I have sql worksheet and sql plus that comes with oracle.

Should I download a free sql tool? Would that assist with connection and sql coding with asp.net?
0
 

Author Comment

by:ernie_shah
ID: 39241078
Thanks for the link
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39242397
I was referring to SQL Plus. Have you tried connecting to Oracle using SQL Plus?
0
 

Author Comment

by:ernie_shah
ID: 39253837
I am able to connect with sql plus
0
 

Author Comment

by:ernie_shah
ID: 39253850
Would oracle version be an issue? I have both Orale 9i and 10g installed on my computer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question