H Foks
I have the following code in a c# class:
I'm trying to pass mValue as an object to a sql server stored proc that expects an image data type and get the following error:
System.InvalidCastException: Invalid cast from System.String to System.Byte[].
Any ideas how I can convert the mValue object data type into an acceptable format for the sql image data type?
Thanks in advance
Smeat
I have the following code in a c# class:
Code:
#region Data Access
internal void PersistSessionData(SqlTransaction Tr, string SessionID)
{
string connectionString = System.Configuration.ConfigurationSettings.AppSettings["DB:ShowroomLog"].ToString();
SqlConnection Cn = new SqlConnection(connectionString);
Cn.Open();
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = Cn;
try
{
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.CommandText = "Core_SaveSessionData";
SqlParameter[] parameters = {new SqlParameter("@SessionID", SqlDbType.NVarChar, 100),
new SqlParameter("@SessionKey", SqlDbType.NVarChar, 50),
new SqlParameter("@SessionValue", SqlDbType.Image) };
parameters[0].Value = SessionID;
parameters[1].Value = mKey;
parameters[2].Value = mValue;
Cmd.Parameters.Add(parameters[0]);
Cmd.Parameters.Add(parameters[1]);
Cmd.Parameters.Add(parameters[2]);
Cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
Cmd.Dispose();
Cmd = null;
Cn.Close();
Cn.Dispose();
}
}
#endregion
I'm trying to pass mValue as an object to a sql server stored proc that expects an image data type and get the following error:
System.InvalidCastException: Invalid cast from System.String to System.Byte[].
Any ideas how I can convert the mValue object data type into an acceptable format for the sql image data type?
Thanks in advance
Smeat