MS访问prepared声明声明、MS、prepared

由网友(以後旳以後,拿命愛自己。)分享简介:是否有可能在VBA中的本地表中的MS Access执行prepared语句:更新零件SET part_description =? WHERE PART_ID =?如果这样是如何做的?解决方案昏暗的分贝作为DAO.DATABASEDIM QDF作为DAO.QueryDef昏暗STRSQL作为字符串设置DB =...

是否有可能在VBA中的本地表中的MS Access执行prepared语句:

 更新零件SET part_description =? WHERE PART_ID =?
 

如果这样是如何做的?

解决方案

昏暗的分贝作为DAO.DATABASE DIM QDF作为DAO.QueryDef 昏暗STRSQL作为字符串 设置DB = CurrentDb STRSQL =UPDATE Month_Totals设置item_date = [which_date]&放大器; _     WHE​​RE ID = [which_id]; Debug.Print STRSQL 设置QDF = db.CreateQueryDef(vbNullString,STRSQL) qdf.Parameters(which_date)。值=日期() qdf.Parameters(which_id)。值= 1 qdf.Execute dbFailOnError

这示例使用了一个新的,未保存的QueryDef 。如果你有一个保存的参数查询,您可以改为代位线为 CreateQueryDef 行使用它:

设置QDF = db.QueryDefs(YourQueryName) 如何建立适合移动端浏览的网站

无论哪种方式,您可以参考各个参数由他们的名字和我一样,或由它们在SQL语句中的位置......所以这将工作与上面相同:

qdf.Parameters(0).value的=日期() qdf.Parameters(1)。价值= 1

其他注意事项:

。价值参数的默认属性,因此它包括在这里并不严格要求。在另一方面,它不会伤害是明确的。 如戈德文所述,您可以使用砰符号与像 QDF参数的名称!which_id ,这比 QDF更简洁。参数(which_id)

Is it possible to execute a prepared statement in MS Access on a local table in VBA like this:

UPDATE part SET part_description=? WHERE part_id=?

If so how is it done?

解决方案

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSql As String
Set db = CurrentDb
strSql = "UPDATE Month_Totals Set item_date = [which_date]" & _
    " WHERE id = [which_id];"
Debug.Print strSql
Set qdf = db.CreateQueryDef(vbNullString, strSql)
qdf.Parameters("which_date").Value = Date()
qdf.Parameters("which_id").Value = 1
qdf.Execute dbFailOnError

That example used a new, unsaved QueryDef. If you have a saved parameter query, you can use it instead by substituting this line for the CreateQueryDef line:

Set qdf = db.QueryDefs("YourQueryName")

Either way, you can then refer to individual parameters by their names as I did, or by their positions in the SQL statement ... so this will work same as above:

qdf.Parameters(0).Value = Date()
qdf.Parameters(1).Value = 1

Additional notes:

.Value is the default property for a Parameter, so including it here is not strictly required. On the other hand, it doesn't hurt to be explicit. As Gord noted below, you can use "Bang notation" with the parameter's name like qdf!which_id, which is more concise than qdf.Parameters("which_id")

阅读全文

相关推荐

最新文章