Professional Web Applications Themes

Problem With Insert into MySQL DB using VB.Net 2005 - MySQL

Hello everyone, I am having a issue inserting values into a MYSQL table, and for the life of me, I can figure out why. I know the connection is successful, however I am getting errors. The table has 4 fields, all of them are Text values. Here is my code: Dim myCommand As New MySqlCommand myCommand.Connection = conn myCommand.CommandText = "INSERT INTO Order(ONUM, Password, Email, Process) " _ & "Values (" _ & "'" & txtOrder.Text & "', " _ & "'" & txtPassword.Text & "', " _ & "'" & txtEmail.Text & "', " _ & "'" & comStatus.SelectedItem ...

  1. #1

    Default Problem With Insert into MySQL DB using VB.Net 2005

    Hello everyone,
    I am having a issue inserting values into a MYSQL table, and for the life of
    me, I can figure out why. I know the connection is successful, however I am
    getting errors.

    The table has 4 fields, all of them are Text values.

    Here is my code:

    Dim myCommand As New MySqlCommand
    myCommand.Connection = conn
    myCommand.CommandText = "INSERT INTO Order(ONUM, Password, Email, Process) "
    _
    & "Values (" _
    & "'" & txtOrder.Text & "', " _
    & "'" & txtPassword.Text & "', " _
    & "'" & txtEmail.Text & "', " _
    & "'" & comStatus.SelectedItem & "')"

    Try
    conn.Open()
    myCommand.ExecuteNonQuery()
    Catch myerror As MySqlException
    MsgBox("There was an error updating the database: " & myerror.Message)
    End Try

    And the error i recieve from it is as follows:
    #42000You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use near
    'Order(ONUM, Password, Email, Process) Values ('353643', '353623542',
    'testhere.' at line 1

    I have also noticed that some of the data I enter on my form is shortened.
    i.e the email address I actually entered on the form was [email]testhere.com[/email]
    however the error message only displays testhere.
    Could anyone help me with my issue?
    Regards


    Materialised Guest

  2. #2

    Default Re: Problem With Insert into MySQL DB using VB.Net 2005

    I think your problem is that the combobox.selecteditem property is an
    object, and you will either need to apply the .Text method or assign it
    to an onject and use the .ToString method.

    zacks@construction-imaging.com Guest

  3. #3

    Default Re: Problem With Insert into MySQL DB using VB.Net 2005

    Hi,

    Like Zack said you should try comStatus.SelectedItem.ToString or
    comStatus.Text in your insert command. A good place for questions about the
    mysql dot net connector is here.

    [url]http://forums.mysql.com/list.php?38[/url]

    Ken
    -------------------
    "Materialised" <materialisedprivacy.net> wrote in message
    news:42hkdjF1iocjaU1individual.net...
    > Hello everyone,
    > I am having a issue inserting values into a MYSQL table, and for the life
    > of me, I can figure out why. I know the connection is successful, however
    > I am getting errors.
    >
    > The table has 4 fields, all of them are Text values.
    >
    > Here is my code:
    >
    > Dim myCommand As New MySqlCommand
    > myCommand.Connection = conn
    > myCommand.CommandText = "INSERT INTO Order(ONUM, Password, Email, Process)
    > " _
    > & "Values (" _
    > & "'" & txtOrder.Text & "', " _
    > & "'" & txtPassword.Text & "', " _
    > & "'" & txtEmail.Text & "', " _
    > & "'" & comStatus.SelectedItem & "')"
    >
    > Try
    > conn.Open()
    > myCommand.ExecuteNonQuery()
    > Catch myerror As MySqlException
    > MsgBox("There was an error updating the database: " & myerror.Message)
    > End Try
    >
    > And the error i recieve from it is as follows:
    > #42000You have an error in your SQL syntax; check the manual that
    > corresponds to your MySQL server version for the right syntax to use near
    > 'Order(ONUM, Password, Email, Process) Values ('353643', '353623542',
    > 'testhere.' at line 1
    >
    > I have also noticed that some of the data I enter on my form is shortened.
    > i.e the email address I actually entered on the form was [email]testhere.com[/email]
    > however the error message only displays testhere.
    > Could anyone help me with my issue?
    > Regards
    >

    Ken Tucker [MVP] Guest

  4. #4

    Default Re: Problem With Insert into MySQL DB using VB.Net 2005

    Materialised wrote:
    > Hello everyone,
    > I am having a issue inserting values into a MYSQL table, and for the life of
    > me, I can figure out why. I know the connection is successful, however I am
    > getting errors.
    >
    > The table has 4 fields, all of them are Text values.
    >
    > Here is my code:
    >
    > Dim myCommand As New MySqlCommand
    > myCommand.Connection = conn
    > myCommand.CommandText = "INSERT INTO Order(ONUM, Password, Email, Process) "


    Order is a reserved word. You will find you cannot even execute 'SELECT
    * FROM Order'. You need to put backticks around `Order`, or chose a
    more suitable table name.



    --
    Brian Wakem
    Email: [url]http://homepage.ntlworld.com/b.wakem/myemail.png[/url]
    Brian Wakem Guest

Similar Threads

  1. Newbie, gridview problem Asp.net 2005
    By verci in forum ASP.NET Building Controls
    Replies: 2
    Last Post: August 28th, 06:36 AM
  2. Problem with MOM 2005 Web console
    By Spale in forum ASP.NET Web Services
    Replies: 0
    Last Post: April 28th, 12:25 PM
  3. id after insert in MySQL
    By Ike in forum PHP Development
    Replies: 1
    Last Post: June 24th, 02:07 AM
  4. insert CSV in mySql problem
    By Richard Sauve in forum PHP Development
    Replies: 1
    Last Post: April 30th, 09:05 PM
  5. php problem array insert into mysql
    By mexiflip in forum PHP Development
    Replies: 0
    Last Post: August 27th, 11:30 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139