Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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'


VB
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();
Posted
Updated 26-Feb-13 16:18pm
v3
Comments
Just eg 27-Feb-13 2:47am    
change
string strSQL = "Update Questions Set QuestionImg = @Img Where QueId = " + RecId;
to
string strSQL = "Update Questions Set QuestionImg = @Img Where QueId = " + RecId & ";"

VB
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
 
Share this answer
 
Comments
mistryshailesh 27-Feb-13 12:59pm    
Thanks for the solution. Code i working fine. but, i m not able to retrieve imgae value in picturebox again
VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900