Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Variable inside an SQL Query? Help please.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    6

    Resolved [RESOLVED] [2005] Variable inside an SQL Query? Help please.

    This is how I thought it was done but everytime I try this I get an error.

    VB Code:
    1. For Each FoundMatch As System.Text.RegularExpressions.Match In Mymatches
    2.             Dim table8 As String = FoundMatch.Value
    3.             MsgBox(table8)
    4.             conn.Execute("CREATE TABLE " & table8 & "(file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, file_name VARCHAR(64) NOT NULL, file_size MEDIUMINT UNSIGNED NOT NULL, file MEDIUMBLOB NOT NULL)")
    5.  
    6.  
    7.         Next

    The error is...

    Code:
    System.Runtime.InteropServices.COMException was unhandled
      ErrorCode=-2147217900
      Message="[MySQL][ODBC 3.51 Driver][mysqld-5.0.18-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '30(file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, file_name VARC' at line 1"
      Source="Microsoft OLE DB Provider for ODBC Drivers"

  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    6

    Re: [2005] Variable inside an SQL Query? Help please.

    One more thing...everything works fine when I'm not trying to place a variable inside the code.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] Variable inside an SQL Query? Help please.

    Use angle quotes (`) around field, table, and database names. Single quotes (') around string literals (be careful to escape any single quotes that might go into those strings with backslashes \'). No quotes around numbers.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    6

    Re: [2005] Variable inside an SQL Query? Help please.

    VB Code:
    1. conn.Execute("CREATE TABLE table8(file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, file_name VARCHAR(64) NOT NULL, file_size MEDIUMINT UNSIGNED NOT NULL, file MEDIUMBLOB NOT NULL)")

    I'm sorry...that's a little too advanced and unclear for me. Could you please point me in the right direction with my current code above ^ table8 is the variable I wanna use.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] Variable inside an SQL Query? Help please.

    VB Code:
    1. conn.Execute( _
    2.   "CREATE TABLE `" + table8 + "` (" + _
    3.   "  `file_id` SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, " + _
    4.   "  `file_name` VARCHAR(64) NOT NULL, " + _
    5.   "  `file_size` MEDIUMINT UNSIGNED NOT NULL, " + _
    6.   "  `file` MEDIUMBLOB NOT NULL)" _
    7. )

    I tested that exact query on a MySQL client with no problems.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    6

    Re: [2005] Variable inside an SQL Query? Help please.

    Thank You!

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