10 Replies - 1464 Views - Last Post: 21 December 2011 - 10:06 AM Rate Topic: -----

#1 mssrivathsan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-October 11

Problem with VB.net Login

Posted 21 December 2011 - 08:48 AM

hey there guys. I have coded my own mysql login program. But I have got a problem with it. I have added the following codes in my program
Dim MySqlConnection As MySqlConnection
        MySqlConnection = New MySqlConnection()

        MySqlConnection.ConnectionString = "server=****; user id=*****; password=******; database=ccloud_login;"
        Try
            MySqlConnection.Open()
        Catch myerror As MySqlException
            MsgBox(myerror.Message)

        End Try
        Try
            Dim myadapter As New MySqlDataAdapter
            Dim sqlquary = "SELECT * FROM register WHERE username = '" & Usernametextbox.Text & "' AND password = '" & Passwordtextbox.Text & "';"
            Dim command As New MySqlCommand
            command.Connection = MySqlConnection
            command.CommandText = sqlquary
            myadapter.SelectCommand = command
            Dim mydata As MySqlDataReader
            mydata = command.ExecuteReader()
            If mydata.HasRows = 0 Then
                MsgBox("Invalid user")
            Else
                MsgBox("Welcome user")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


The problem with it is that, even if I enter a correct username and password it shows the "Invalid User" message. I have checked the username and password a thousand times. Please help me out in this problem..

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with VB.net Login

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem with VB.net Login

Posted 21 December 2011 - 08:52 AM

Are you familiar with breakpoints and debugging?

Then see FAQ #5 for debugging tutorials


FAQ (Frequently Asked Questions - Updated Nov 2011

Spoiler

Was This Post Helpful? 0
  • +
  • -

#3 mssrivathsan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-October 11

Re: Problem with VB.net Login

Posted 21 December 2011 - 08:54 AM

but what is the use of breakpoints here ?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem with VB.net Login

Posted 21 December 2011 - 08:59 AM

You walk through the execution of your application line by line.
You check the ACTUAL values of variables to what you THINK they should be.
You watch the execution take paths you didn't expect and determine why.
Was This Post Helpful? 0
  • +
  • -

#5 mssrivathsan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-October 11

Re: Problem with VB.net Login

Posted 21 December 2011 - 09:04 AM

But could you the exact solution for my problem. I cant get what you are about to say.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9277
  • View blog
  • Posts: 34,788
  • Joined: 12-June 08

Re: Problem with VB.net Login

Posted 21 December 2011 - 09:05 AM

A few things. First - why is your 'mysqlconnection.open' in a different try/catch? Might as well lump them all in one because if the connection doesn't open why try the rest? Second, try and not declare variables inside try/catches. It becomes a pain in the ass to debug when your variables are losing scope at the end of the try/catch.

Walk through your code (slap a breakpoint and step through each line) - I think you'll find the issue when you look at the variables and actors involved.

You:
1. open a connection
2. create a commandobject
3. set the command object's connection and query
4. assign the command to the myadapter.select command.
5. create a data reader
6. the data reader get's the command executing the reader

why go through the work of an adapter if you won't use it? Personally I am a fan of:
1. open the connection
2. set the adapter to the sql query and teh connection
3. create a dataset
4. use the adapter's ".fill" with the dataset.
5. check the rows off that dataset.

http://dev.mysql.com...ataadapter.html

--
edit: damn.. tlhin beat me to it.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem with VB.net Login

Posted 21 December 2011 - 09:09 AM

View Postmssrivathsan, on 21 December 2011 - 10:04 AM, said:

But could you the exact solution for my problem. I cant get what you are about to say.


What I'm trying to say is that it is more important for you to learn how to debug your own applications than for someone to just hand you the solution. You can't expect others to do your debugging for your, for your entire career, just because you don't want to take the time to do it yourself, or don't want to learn to do it yourself.

Debugging is a vital part of coding. Many times more time is spent on debugging than actual coding. And it is through debugging that you start finding the problems in your own understanding of the concepts of your code.

Did you even look at the links I gave you?
http://www.dreaminco...-common-errors/

You responded so fast to this thread I don't see how you could have even tried the tutorials.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem with VB.net Login

Posted 21 December 2011 - 09:18 AM

Here is a little help on HOW to figure out the issue for yourself. How to debug this.

The bug is that it always reports 'invalid user'.
Ok - Under what conditions can that happen?
It can only happen if mydata has zero rows
            If mydata.HasRows = 0 Then
                MsgBox("Invalid user")
            Else
                MsgBox("Welcome user")
            End If


So work backwards from there. Where does mydata come from?
It is the result of your command query on the database.
 mydata = command.ExecuteReader()


So it makes sense you need to double-check all the assumptions of the command and the connection to the database.

Do you understand now a little better how to track down the problem?
Was This Post Helpful? 1
  • +
  • -

#9 mssrivathsan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-October 11

Re: Problem with VB.net Login

Posted 21 December 2011 - 09:21 AM

@#8 tlhIn`toq Yeah thanks. I got some ideas on how to debug
Was This Post Helpful? 0
  • +
  • -

#10 mssrivathsan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 10-October 11

Re: Problem with VB.net Login

Posted 21 December 2011 - 10:02 AM

Well finally found out the solution after struggling for 8 hours. The problem was with the server which i used. Such an idiot i am. I should have thought about it earlier -_- :oops: :oops: :oops:
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Problem with VB.net Login

Posted 21 December 2011 - 10:06 AM

Glad to see a fresh set of eyes and little guidance in how to figure it out, helped you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1