开发者

ASP.net SQL database amend existing string field data using command parameters

I am trying to maintain a log field (fldUserLog ) of my database table so that when updating each raw, the log field will be amended with given log string.

Log string

 strUserLog = "Added by : " & Session("auth_Id") &am开发者_JS百科p; " at " & Now() & " from IP " &
      Request.ServerVariables("REMOTE_ADDR") & vbCrLf

and I am using SQL command parameters to UPDATE query. as follows

strSQLQuery = "UPDATE myTable SET " _
    & "fldTitle  = @xTitle, " _
    & "fldDesc  = @xDesc, " _
    & "fldUserLog = fldUserLog + @xUserLog " _
    & "WHERE fldId = @xId ;"

strMessage = "updated"

ObjAddDB.setCommand(strSQLQuery)
With ObjAddDB
    .setParameters("@xTitle", frmTitle.Text)
    .setParameters("@xDesc", frmDesc.Text)
    .setParameters("@xUserLog", strUserLog)
    .setParameters("@xId", MyItemId)
End With

Please note that setCommand and setParameters are my own methods I am using in my database.vb class file.

I get following error when its executed

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'fldUserLog'.

please help me to use my UPDATE query to amend existing data with command parameters.


If the format of the fldUserLog field value contains spaces, you need to embrace the value with [ ] ..

& "fldUserLog = [fldUserLog @xUserLog] " _

I guess what you may want to write is the following:

& "fldUserLog = @xUserLog " _
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜