帮助在vb.net中更新查询 [英] Help with update query in vb.net
问题描述
大家好我有以下查询,此查询在MS Access的查询构建器中正常工作:
Hi everyone I have the following query, this query works fine in the query builder in MS Access:
UPDATE PAYTEST SET PAYTEST.ImageName = "C:\Ezc\Files\" & [bates] & " *.TIF";
Howerver当我尝试从vb.net执行时,它不起作用。
这是我的vb.net代码:
Howerver when I try to execute in from vb.net, It does not work.
Here is my vb.net code:
Public Shared Function UpdateImagePathSQL(ByVal newPath As String) As Integer
Dim cn As OleDbConnection
Dim intNumberOfRecordsUpdated As Integer
Try
cn = New OleDbConnection
cn.Open()
Dim selectStatement As String
selectStatement = _
"UPDATE Paytest SET Imagename = '" & newPath & "'" & "\[bates].TIF"
Dim cmd = New OleDbCommand(selectStatement, cn)
intNumberOfRecordsUpdated = cmd.ExecuteNonQuery()
cn.Close()
MessageBox.Show("Records updated sucessfully", "Timesheet imagepath update")
Return intNumberOfRecordsUpdated
Catch ex As Exception
MessageBox.Show(ex.Message, "Error updating image path")
cn.Close()
End Try
[bates]是我的访问表中的一个字段,其中包含没有扩展名的图像名称。
我是什么做错了吗?
谢谢
Ed
[bates] is a field in my access table that contains the image name without the extension.
What Am I doing wrong?
Thanks
Ed
推荐答案
我想,你对更新查询有疑问,请查看下面的内容。
Hi,
I think, you problem with the update query, check the below.
selectStatement = _
"UPDATE Paytest SET Imagename = '" & newPath & "\[bates].TIF'"
最好的问候
Muthuraja
Best Regards
Muthuraja
您好,
此查询在MS Access的查询生成器中正常工作:
Hi,
This query works fine for you in the query builder in MS Access:
UPDATE PAYTEST SET PAYTEST.ImageName = "C:\Ezc\Files\" & [bates] & " *.TIF";
And这是 selectStatement
:
And this is selectStatement
:
Dim selectStatement As String
selectStatement = _
"UPDATE Paytest SET Imagename = '" & newPath & "'" & "\[bates].TIF"
在 selectStatement
中,将 Imagename
更改为 PAYTEST.Imagename
和付费
进入 PAYTEST
。
另外,你需要把第二个撇号在文件路径之后:
In selectStatement
, change Imagename
into PAYTEST.Imagename
, and Paytest
into PAYTEST
.
Also, you need to put the second apostrophe AFTER the file path:
Dim selectStatement As String
selectStatement = _
"UPDATE PAYTEST SET PAYTEST.Imagename = '" & newPath & "\[bates].TIF'"
希望这会有所帮助。
Hope this helps.
我尝试了两种消化方式,不幸的是它们都没有工作。
我得到一个例外:
I tryed both sugestion and unfortunatelly none of them work.
I get an exception:
System.Data.OleDb.OleDbException was caught
ErrorCode=-2147217904
Message="No value given for one or more required parameters."
Source="Microsoft JET Database Engine"
例如,如果bates包含IMG0002并且新路径的值为C:\ImgPath \ImageName的最终结果应为C:\ImgPath \IMG0002.TIF但是当我运行查询时,结果为C:\ ImgPath \ [bates] .TIF这是错误的,因为[bates]是我MS Access表格中的一个字段。
其他任何消息?
非常感谢。
Ed
For example if bates contains "IMG0002" and the value of new path is "C:\ImgPath\" The final result of ImageName should be "C:\ImgPath\IMG0002.TIF" however when I run the query the result is "C:\ImgPath\[bates].TIF" which is wrong because [bates] is a field in my MS Access table.
Any other sugestions?
Thanks very much.
Ed
这篇关于帮助在vb.net中更新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!