EddieAdams Posted July 25, 2008 Posted July 25, 2008 With a MySQL database I want to get a value from a column name. But the column name is a a variable.CODE.Fields($columnName).valueThis outputs an error:==> Error in expression.Any ideaS?
ResNullius Posted July 25, 2008 Posted July 25, 2008 With a MySQL database I want to get a value from a column name. But the column name is a a variable. CODE.Fields($columnName).value This outputs an error: ==> Error in expression. Any ideaS?What is your surrounding code? Are you trying to store the value in a variable too? MsgBox it? Write it to a file? Are you using a "With" statement, $columnName = "LastName" With $oMySqlDb $colValue = .Fields($columnName).value EndWith or does the database object reference come in line before this, $columnName = "LastName" $colValue = $oMySqlDb.Fields($columnName).value We need to see more to tell more!
EddieAdams Posted July 25, 2008 Author Posted July 25, 2008 CODE Func FuncName() $SQLOBJ = _MySQLConnect($UserName,$Password,$Database,$MySQLServerName) $SQLCode = "SELECT * FROM tbl_Name'" $TableContents = _Query($SQLOBJ,$SQLCode) $columnName = "columnName" $NameList = "" With $TableContents While Not .EOF $NameList &= $SQLCode & ", " & .Fields("cards").value & ", " & .Fields($columnName).value & @CRLF .MoveNext WEnd EndWith _MySQLEnd($SQLOBJ) ConsoleWrite($NameList & @LF) ; debug info EndIf Next EndFunc ; =>
ResNullius Posted July 26, 2008 Posted July 26, 2008 $columnName = "columnName"Is the column name in the table literally "columnName" ??? If so, I will dig a little deeper (and whoever designed the table should be shot!) If not, replace it with the actual name of the column. Also, are you very experienced with SQL , ADO, and the like? Or a bit of a noob? Just need to know so I don't take make certain assumptions one way or the other
EddieAdams Posted July 26, 2008 Author Posted July 26, 2008 (edited) No, I changed it to columnname for this example. Noob nor expert. Edited July 26, 2008 by EddieAdams
EddieAdams Posted July 26, 2008 Author Posted July 26, 2008 The original script doesnt have a preserved column name.
ResNullius Posted July 26, 2008 Posted July 26, 2008 No, I changed it to columnname for this example. Noob nor expert.OK, first try this Func FuncName() $SQLOBJ = _MySQLConnect($UserName,$Password,$Database,$MySQLServerName) $SQLCode = "SELECT * FROM tbl_Name'" $TableContents = _Query($SQLOBJ,$SQLCode) $columnName = "columnName" $NameList = "" With $TableContents While Not .EOF $colValue = .Fields($columnName).value ConsoleWrite($colValue & @CRLF) .MoveNext WEnd EndWith _MySQLEnd($SQLOBJ) EndFunc; => See if that outputs the values as expected. Note: in you orginal function as posted above, you have an orphaned EndIf and an orphaned Next statement. Don't know if they're there in your production code, but they should be removed.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now