Results 1 to 8 of 8

Thread: [RESOLVED] i have a quetion regarding with mysql to vb.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    137

    Resolved [RESOLVED] i have a quetion regarding with mysql to vb.net

    SQL = "SELECT * FROM `cf_users` WHERE `email` = '" + txtEmail.Text + "' AND `password` = '" + txtPassword.Text + "'"

    My question is it necessary 2 put a ' in the query cause im having a error if i will not include the ' sign in my sql query. . . .

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: i have a quetion regarding with mysql to vb.net

    No you shouldn't have quotes around field names, just around strings.

    You should also be using parameters in your query rather than just inserting values from your textbox.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: i have a quetion regarding with mysql to vb.net

    you get an error because password is a reserved word in mySQL ... so you can either change the name of the field to something else, or keep the ` marks around it (just the password field name).

    keystone - normally I agree but in this case ` and ' are different... the first is used as the quoted object delimiter (similar to the brackets in Access or SQL Server)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    137

    Re: i have a quetion regarding with mysql to vb.net

    I'm comparing my user id and my password to my sql if they are the same. . . .when i erase the ' in my like this '" + txtEmail.Text + "' it will give me errors and if i erase dis in my last line + "'". . . .juz can't understand it nobody's teaching with this quote ' what is the use of this in vb.net? the '. . . .please elp me with this. . . .

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: i have a quetion regarding with mysql to vb.net

    the ' signifies a STRING value in SQL ... the fact that "nobody's teaching with this quote" ... is bogus... because if that was true, then EVERYone would be using parameters (as they should be) and we wouldn't be having this discussion.

    That said... I reallllllllllllly encourage you to read our database faq and tutorial section, ESPECIALLY with parameters and use them... it will save you a lot of time effort trouble and heartburn in the long run.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    137

    Re: i have a quetion regarding with mysql to vb.net

    where can i find the database faq and tutorial section??Nid 2 learn ASAP cause we have a project using mysql and im the programmer i dont know what to do. . . .

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: i have a quetion regarding with mysql to vb.net

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    137

    Re: i have a quetion regarding with mysql to vb.net

    it is ok if i remove the single quote in my query??but it will give me some errors though not like in my connection string. . . .This is my code that my friend wrote and he use the single quote in his query. . . .

    vb Code:
    1. Imports MySql.Data.MySqlClient
    2. Public Class Form1
    3.     Dim conn As New MySqlConnection
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         conn.ConnectionString = "server=localhost;" _
    7.        & "user id=root;" _
    8.        & "password=root;" _
    9.        & "database=User_account"
    10.         Try
    11.             'Try to open the connection
    12.             conn.Open()
    13.  
    14.         Catch ex As MySqlException
    15.             'If fail will show a MySQL Error
    16.             MsgBox(ex.Message)
    17.         End Try
    18.     End Sub
    19.  
    20.     Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlogin.Click
    21.         Dim myCommand As New MySqlCommand
    22.         Dim myAdapter As New MySqlDataAdapter
    23.         Dim myData As MySqlDataReader
    24.  
    25.         Dim SQL As String
    26.         'Our MySQL Query
    27.         SQL = "SELECT * FROM account WHERE User_name = '" + TextBox1.Text + "' AND User_pass = '" + TextBox2.Text + "'"
    28.  
    29.         myCommand.Connection = conn
    30.         myCommand.CommandText = SQL
    31.         myAdapter.SelectCommand = myCommand
    32.         Try
    33.             'Try to execute the query
    34.             myData = myCommand.ExecuteReader()
    35.             myData.Read()
    36.             If myData.HasRows = 0 Then 'Checkes if a row with the email and password exist.
    37.                 'If no outputs this:
    38.                 MsgBox("Username and Password dont match!.")
    39.                 myData.Close()
    40.             Else
    41.                 'if yes outputs this:
    42.                 MsgBox("Welcome " + "This is me" + "!.")
    43.                 myData.Close()
    44.  
    45.             End If
    46.         Catch ex As MySqlException
    47.             'If fail outputs MySQL Error
    48.             MsgBox(ex.Message)
    49.         End Try
    50.     End Sub
    51. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width