Vb.net将varbinary值插入访问数据库 [英] Vb.net inserting a varbinary value into an access databae

查看:76
本文介绍了Vb.net将varbinary值插入访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在尝试使用以下代码使用以下代码将文件插入Access数据库中的VarBinary字段:



'SQLStr = UPDATE [Documents]设置[EmbeddedDocument] = @ EmbeddedDocument WHERE [Project] ='test'和[hole_id] ='test'; 

Dim命令As New OdbcCommand(SQLStr,x.Connection)
'command.Parameters.AddWithValue(Parametername,ByteStream)
command.Parameters.Add(Parametername,OdbcType.VarBinary ).Value = ByteStream
command.Parameters(0).Size = ByteStream.Length

command.ExecuteNonQuery()
command.Dispose()





我收到错误'预期参数太少'但无法弄清楚它出错的地方。我试过.Add和.Addwithvalue我可以看到参数已被添加到命令对象的参数上,但没有快乐!



谢谢



Steve



我的尝试:

<除了工作的东西

解决方案

使用调试器并检查参数名称:是 Parametername 设置正确吗?如果不是,Odbc引擎将无法将其与SQL语句中的参数匹配,您将收到错误消息。

同时检查 ByteStream 并确保那里有数据(不太可能出现问题,但如果你有调试器,请检查)。

尝试更改为:

 SQLStr =UPDATE [Documents]设置[EmbeddedDocument] = @ ED WHERE [Project] ='test'和[hole_id] ='test'; 
Dim命令As New OdbcCommand(SQLStr,x.Connection)
command.Parameters.AddWithValue(@ ED,ByteStream)

并查看是否修复了它。


似乎有用的是:



 SQLStr =UPDATE [Documents]设置[EmbeddedDocument] =? WHERE [Project] ='test'和[hole_id] ='test'; 
Dim命令As New OdbcCommand(SQLStr,x.Connection)
command.Parameters.AddWithValue(@ ED,ByteStream)





我不确定这是否是ODBC驱动程序的特性?


嗨OG,不幸的是我仍然得到同样的错误。我已将参数名称更改为与字段名称(@P)不同的名称,结果相同。


Hi All

I am trying to use following code to insert a file into a VarBinary field in an Access database using the following code :

'SQLStr = 	UPDATE [Documents] Set [EmbeddedDocument]=@EmbeddedDocument WHERE [Project]='test' AND [hole_id]='test';

Dim command As New OdbcCommand(SQLStr, x.Connection)
' command.Parameters.AddWithValue(Parametername, ByteStream)
 command.Parameters.Add(Parametername, OdbcType.VarBinary).Value = ByteStream
 command.Parameters(0).Size = ByteStream.Length
                    
command.ExecuteNonQuery()
command.Dispose()



I get the error 'Too few parameters expected 1' but can't figure out where it is going wrong. I have tried .Add and .Addwithvalue and I can see the parameter has been added to the parameters on the command object, but no joy!

Thanks

Steve

What I have tried:

Everyting except the thing that works

解决方案

Use the debugger and check the parameters names: is Parametername set correctly? If it isn't, the Odbc Engine won't be able to match it with the parameter in the SQL statement and you will get the error message.
Also check the value of ByteStream and ensure there is data there (unlikely to be the problem but if you have the debugger there, check anyway).
Try changing to:

SQLStr = "UPDATE [Documents] Set [EmbeddedDocument]=@ED WHERE [Project]='test' AND [hole_id]='test';"
Dim command As New OdbcCommand(SQLStr, x.Connection)
command.Parameters.AddWithValue("@ED", ByteStream)

And see if that fixes it.


What seems to work is this:

SQLStr = "UPDATE [Documents] Set [EmbeddedDocument]=? WHERE [Project]='test' AND [hole_id]='test';"
Dim command As New OdbcCommand(SQLStr, x.Connection)
command.Parameters.AddWithValue("@ED", ByteStream)



I'm not sure if that is a peculiarity of the ODBC driver?


Hi OG, unfortunately I still get the same error. I have changed parameter name to a different name to the field name (@P), with the same result.


这篇关于Vb.net将varbinary值插入访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆