Solved

Login Button - Not working

Posted on 2013-06-11
11
276 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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