General information
Category:
The Mere Mortals .NET Framework
Title:
Insert Image data into SQL server using IDbDataParameter
Hi,
I am trying to insert a image data into sql server using MM .NET Framework, and I have tried different datatypes, and it did not work. The error tells me that "Line 1: Incorrect syntax near 'ADD_CACHE_ITEM'."
I tried to do the same thing with Sqlclient, and it worked. The difference is I used SqlDbType.Image instead of DbType.Binary or DbType.Object.
Any help is appreciated.
Here is the code that DONOT WORK:
//create a dataset
DateSet ds = GetDateSet();
byte[] serializedDS;
//serialize to binary
serializedDS = SerializationUtility.ToBytes (ds);
IDbDataParameter myParams;
myParams = this.CreateParameter("@VALUE",serializedDS);
myParams.DbType = DbType.Binary;
//myParams.DbType =DbType.Object;
this.ExecNonQuery ("ADD_CACHE_ITEM", myParams);
Here is the code that works:
//create a dataset
DateSet ds = GetDateSet();
byte[] serializedDS;
//serialize to binary
serializedDS = SerializationUtility.ToBytes (ds);
SqlCommand command = new SqlCommand ("ADD_CACHE_ITEM", connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter param0 = new SqlParameter( "@VALUE", serializedDS);
param0.SqlDbType = SqlDbType.Image;
command.Parameters.Add(param0);
command.ExecuteNonQuery ()
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only