Results 1 to 7 of 7

Thread: MySQL and Query (Allias) ***RESOLVED***

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved MySQL and Query (Allias) ***RESOLVED***

    Can someone tell me why I am getting an error for the the following sql statement when I execute it against a MySQL Database. This sql statement works great with MSSQL and Access:

    VB Code:
    1. Dim strFieldName as String
    2. Dim strTableName as String
    3.  
    4. strFieldName = "MyFieldName"
    5. strTableName = "MyTableName"
    6.  
    7. strSQL = "SELECT " & strFieldName & " as FieldName " '<==Aliasing MyFieldName as fieldname
    8. strSQL = strSQL & "FROM " & strTableName & " "

    then I attempt to Add a new record into the table:

    VB Code:
    1. rs.AddNew
    2.         strValue = Me.Text1.Text
    3.         rs!FieldName = strValue & ""
    4.         rs.Update  '<====This is the line I get the error on

    I get the following error message: Error -214721900 (Unknown column 'fieldname' in 'field list)

    Am I to assume that MySQL doesn't allow you to allias fieldnames?

    If I change the fieldname to the following:

    VB Code:
    1. Dim strFieldName as String
    2. Dim strTableName as String
    3.  
    4. strFieldName = "MyFieldName"
    5. strTableName = "MyTableName"
    6.  
    7. strSQL = "SELECT " & strFieldName & " " 'as FieldName " <==Aliasing MyFieldName as fieldname
    8. strSQL = strSQL & "FROM " & strTableName & " "

    VB Code:
    1. rs.Fields(0).Value = strValue & ""

    it works fine, any ideas??

    P.S. I am using mysql-4.1.12-win32 version
    Last edited by Mark Gambo; May 30th, 2005 at 07:38 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MySQL and Query (Allias)

    What does the actual SQL statement look like?

    Debug.Print strSQL

  3. #3
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Manila, Philippines
    Posts
    486

    Re: MySQL and Query (Allias)

    check the spelling of your fieldname, if it correspond to this " strValue & "" "

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: MySQL and Query (Allias)

    Quote Originally Posted by randem
    What does the actual SQL statement look like?

    Debug.Print strSQL
    Here is the actual SQL:

    VB Code:
    1. strSQL = "SELECT MyFieldName as FieldName FROM MyTableName"

    I don't think it is a problem with the SQL because like I said in my first post this same sql statement when executed against a MS SQL and Access Databases it works fine.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MySQL and Query (Allias)

    Mark Gambo,

    That is an incorrect assumption. Reserved words in one database are not necessarily reserved in another. Try making it look like this:

    strSQL = "SELECT MyFieldName as [FieldName] FROM MyTableName"

    or just change the name of the alias.

  6. #6

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: MySQL and Query (Allias)

    Quote Originally Posted by randem
    Mark Gambo,

    That is an incorrect assumption. Reserved words in one database are not necessarily reserved in another. Try making it look like this:

    strSQL = "SELECT MyFieldName as [FieldName] FROM MyTableName"

    or just change the name of the alias.
    That is a good idea, I will give it a try.

    Thanks!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: MySQL and Query (Allias)

    Quote Originally Posted by Mark Gambo
    Here is the actual SQL:

    VB Code:
    1. strSQL = "SELECT MyFieldName as FieldName FROM MyTableName"

    I don't think it is a problem with the SQL because like I said in my first post this same sql statement when executed against a MS SQL and Access Databases it works fine.
    Well I figure it out:

    VB Code:
    1. strSQL = "SELECT " & [color="#FF0000"]strFieldName[/color] & " "
    2.         strSQL = strSQL & "FROM " & strTableName & " "
    3.  
    4.         rs.AddNew
    5.         strValue = Me.Text1.Text
    6.         [color="#FF0000"]rs(strFieldName)[/color] = strValue & ""
    7.         rs.Update
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


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