Solved

Login Button - Not working

Posted on 2013-06-11
11
272 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
  • 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now