VB.NET 2005 ODBCCommand
-
Hi All; I'm writing a small app that is displaying information in a datagridview from a FoxPro table. I am having issues on the update side of things. I am trying to write my own update statements using the ODBCCommand object, and parameters. However, the statement is failing, with only the message of Syntax Error. When I try to get the actual command text, it shows the sql statement with the @VarName placeholders. Is there anyway to get the final sql statement? Or should it show as the command text, and I am setting this up wrong. Here is what I am doing:
sql = "UPDATE table1 SET Descript = @Desc " sql += "WHERE RefNum = @RefNum " cmd.CommandText = sql parm = New OdbcParameter("@desc", SqlDbType.Char, 120) parm.Value = oRow.Item("description").ToString().Trim() cmd.Parameters.Add(parm) parm = New OdbcParameter("@refnum", SqlDbType.Char, 12) parm.Value = oRow.Item("ref num").ToString().Trim() cmd.Parameters.Add(parm) cmd.ExecuteNonQuery() 'This fails with Syntax Error
This is a shortened version, there are around 15 variables I am using. When I check the value of CommandText, it shows as: "UPDATE table1 sET Descript = @Desc WHERE RefNum = @RefNum" I am guessing this is what it should show, but is there anyway to see what is actually being sent to execute? Thanks -
Hi All; I'm writing a small app that is displaying information in a datagridview from a FoxPro table. I am having issues on the update side of things. I am trying to write my own update statements using the ODBCCommand object, and parameters. However, the statement is failing, with only the message of Syntax Error. When I try to get the actual command text, it shows the sql statement with the @VarName placeholders. Is there anyway to get the final sql statement? Or should it show as the command text, and I am setting this up wrong. Here is what I am doing:
sql = "UPDATE table1 SET Descript = @Desc " sql += "WHERE RefNum = @RefNum " cmd.CommandText = sql parm = New OdbcParameter("@desc", SqlDbType.Char, 120) parm.Value = oRow.Item("description").ToString().Trim() cmd.Parameters.Add(parm) parm = New OdbcParameter("@refnum", SqlDbType.Char, 12) parm.Value = oRow.Item("ref num").ToString().Trim() cmd.Parameters.Add(parm) cmd.ExecuteNonQuery() 'This fails with Syntax Error
This is a shortened version, there are around 15 variables I am using. When I check the value of CommandText, it shows as: "UPDATE table1 sET Descript = @Desc WHERE RefNum = @RefNum" I am guessing this is what it should show, but is there anyway to see what is actually being sent to execute? ThanksWhenever I've used parameters, I've always had to do a cmd.DeriveParameters before I could set the parameters value...I'm not sure if it is a required call but you may want to look into it. Also, I do not believe there is a way during debugging to see what the actual statement being sent is. You could try putting in a try-catch block and quickwatching the exception, it may have more detailed error messages. Hope this helps.
-
Whenever I've used parameters, I've always had to do a cmd.DeriveParameters before I could set the parameters value...I'm not sure if it is a required call but you may want to look into it. Also, I do not believe there is a way during debugging to see what the actual statement being sent is. You could try putting in a try-catch block and quickwatching the exception, it may have more detailed error messages. Hope this helps.
I dont think that cmd.DeriveParameters is a valid statement in vb.net, at least not for an OdbcCommand. I thought about the try-catch, just reports the same error, "Syntax Error". I really hate FoxPro...
And now, adding color, a group of anonymous Latin American meat packing glitterati