从vb.net更新ms access 2007中的ole对象字段 [英] update ole object field in ms access 2007 from vb.net
本文介绍了从vb.net更新ms access 2007中的ole对象字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从c#.net更新ms access 2007中的ole对象字段?
以下是我写的代码,但是给了我错误
''没有给出一个或多个参数的值''
How can i update an ole object field in ms access 2007 from c#.net?
Following is the code i have written but is giving me error
''No Value given for one or more parameters''
FileStream fs = default(FileStream);
fs = new FileStream(imgName, FileMode.Open, FileAccess.Read);
byte[] picByte = new byte[fs.Length];
fs.Read(picByte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
string strSQL = "Update Questions Set QuestionImg = @Img Where QueId = " + RecId;
OleDbCommand cmd = new OleDbCommand(strSQL, new OleDbConnection(conn));
OleDbParameter imgParam = new OleDbParameter();
imgParam.OleDbType = OleDbType.Binary;
imgParam.ParameterName = "Img";
imgParam.Value = picByte;
cmd.Parameters.Add(imgParam);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
cmd.Dispose();
推荐答案
Function Update(ByVal RecId As Integer, ByVal Imge As Byte()) As Boolean
Dim Ret As Boolean = True
Using oCn As New OleDb.OleDbConnection(StrConnection)
Try
oCn.Open()
Using oCmd As New OleDb.OleDbCommand()
oCmd.Connection = oCn
oCmd.CommandText = "Update Questions Set QuestionImg = @Img Where QueId = " + RecId & ";"
oCmd.CommandType = CommandType.Text
oCmd.Parameters.Add(New OleDb.OleDbParameter("@Img", OleDb.OleDbType.Binary, 2147483647, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, IIf(IsNothing(Imge), DBNull.Value, Imge)))
oCmd.ExecuteNonQuery()
End Using
Catch ex As Exception
Throw New Exception("_TBIMAGE::Update::Error Occured.", ex)
Ret = False
End Try
End Using
Return Ret
End Function
PictureBox1.Image = GetBitmapFromByte("ImageFieldName")
Function GetBitmapFromByte(ImgRecord As Byte) As Bitmap
Dim _MyImage As Bitmap
If (Not IsNothing(ImgRecord)) Then
Using ms As New IO.MemoryStream(ImgRecord)
_MyImage = New Bitmap(ms)
ms.Close()
End Using
Else
_MyImage = Nothing
End If
Return _MyImage
End Function
这篇关于从vb.net更新ms access 2007中的ole对象字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文