OleDbParameter ,help!!

  • Thread starter Thread starter bby
  • Start date Start date
B

bby

what's wrong?

string SQL="update D_User set Photo=@Photo where ID=@ID";
OleDbCommand myCommand=new OleDbCommand (SQL,connection);
OleDbParameter myParm1 =new OleDbParameter("@ID",OleDbType.Integer,4);
myParm1.Value = 4
myCommand.Parameters.Add(myParm1);

OleDbParameter myParm2 =new OleDbParameter("@Photo",SqlDbType.Binary);
myParm2.Value = imgdata; //is byte[]
myCommand.Parameters.Add(myParm2);

connection.Open();
myCommand.ExecuteNonQuery(); //wrong line,@Photo is not announceed
connection.Close();
 
Hi,

OleDb accepts ? as parameter instead of @name.
"update D_User set Photo=? where ID=?"

Then add OleDbParameters to command in the same order as they appear in the
statement.
 
Hi bby,

Well, you specify OleDbParameter @Photo but you assign a SqlDbType to it
instead of OleDbType.
Furthermore, in some cases named parameters won't be accepted and you need
to put ? for each parameter in the sql string. The parameters need to be
added in the correct order in this case.
 
thanks

i have raveled out!
but only one Paremeter.

-------------------------
string SQL="update D_Table set Photo=? where ID="+Rid;
OleDbCommand myCommand=new OleDbCommand (SQL,connection);

OleDbParameter myParm =new OleDbParameter("@Photo",OleDbType.Binary);
myParm.Value = imgdata;
myCommand.Parameters.Add(myParm);
connection.Open();
myCommand.ExecuteNonQuery();
connection.Close();

-------------------------
maybe is SqlClient Model is:

string SQL="update D_Table set Photo=@Photo where ID="+Rid;
SqlCommand myCommand=new SqlCommand (SQL,connection);
SqlParameter myParm =new SqlParameter("@Photo",SqlDbType.Image);
myParm.Value = imgdata;
myCommand.Parameters.Add(myParm);
connection.Open();
myCommand.ExecuteNonQuery();
connection.Close();

am i right?
 
Back
Top