我在使用basic4android时遇到了更新sql db(Lover.db)中的记录的问题。这有效:
SQLLover.ExecNonQuery("UPDATE Profiles SET Mobile ='Nos', " & _
"Name = 'Nme', Sunday = 'SundayX', Monday = 'MondayX', " & _
"Tuesday = 'TuesdayX', Wednesday = 'WednesdayX', Thursday = 'ThursdayX', " & _
" Friday = 'FridayX', Saturday = 'SaturdayX', " & _
"StartTime = 'lblTimeFrom.text', EndTime = 'lblTimeTo.Text' " & _
"WHERE Mobile='07xxxxxxxxx' AND Name='Sam'")
但当然只是单引号中的数据更新。我想使用一些变量,并试过这个;
SQLLover.ExecNonQuery2("Update Profiles SET(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", & _
Array As Object(Nos, Nme, SundayX, MondayX, TuesdayX, WednesdayX, & _
ThursdayX, FridayX, SaturdayX, lblTimeFrom.Text, lblTimeTo.Text))
这是正确的语法吗?当然,Nos
,Nme
,SundayX
等是我的变量。
答案 0 :(得分:0)
您的UPDATE
语法完全错误。正确的语法是UPDATE table SET column = value, column2 = value2
,依此类推。你的代码甚至没有做任何事情。我不打算整理出整件事,但我会尽力让你开始:
SQLLover.ExecNonQuery2("Update Profiles " & _
"SET Mobile = ?, Name = ?, Sunday = ?, Monday = ?", & _
Array As Object(Nos, Nme, SundayX, MondayX))
答案 1 :(得分:0)
使用您的代码,工作的代码,为了能够在查询中使用变量,您必须转义查询并连接变量。看看这个简短的例子
SQLLover.ExecNonQuery("UPDATE Profiles SET Mobile = ' " & NOs & " ', Name = ' "&NMe & " ' WHERE Name = ' " & OldNameVariable & " ' ")
可以使用VARIABLE插入"& VARIABLENAME &" 如示例所示(Mobile ='"& Nos&"')
提示:最后一个查询应如下所示:AND Name =' " &安培; SamOldVariableName&的" ' " 强>)