Solved

Login Button - Not working

Posted on 2013-06-11
11
275 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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