Hi,
I am trying to insert a record into a database table, one field of which is
a byte array.
Using the below:
Byte[] imgArr;
.... <code to put image into imgArr>
String sbSQL = "INSERT INTO qlink (qlink_name, qlink_start, qlink_end,
qlink_image, qlink_allday, "
+ "qlink_am, qlink_pm, qlink_default_t ext, qlink_default_n otes) VALUES ('"
+ ButtonCaption + "', '" + DefaultStartTim e + "', '" + DefaultEndTime + "',"
+ imgArr + ", " + Convert.ToInt16 (AllDay) + ", " + Convert.ToInt16 (AMOnly)
+ ", " + Convert.ToInt16 (PMOnly) + ", '" + DefaultDescript ion.Replace("'" ,
"''")
+ "', '" + DefaultNotes.Re place("'", "''") + "');";
SqlCommand sbCMD = new SqlCommand(sbSQ L, dbConn);
try
{
sbCMD.ExecuteSc alar();
}
But it fails when the query executes, because in my SQL, imgArr has been
replaced by "System.Byt e[]" (i.e. what the "ToString() " method would do)
rather than the array of bytes...
So, I understand why it's doing it, but how do I get around it? Googling
I've seen mention of using command builders and datasets or datatables and
parameters and so on, but it seems like a load more work!
James.
I am trying to insert a record into a database table, one field of which is
a byte array.
Using the below:
Byte[] imgArr;
.... <code to put image into imgArr>
String sbSQL = "INSERT INTO qlink (qlink_name, qlink_start, qlink_end,
qlink_image, qlink_allday, "
+ "qlink_am, qlink_pm, qlink_default_t ext, qlink_default_n otes) VALUES ('"
+ ButtonCaption + "', '" + DefaultStartTim e + "', '" + DefaultEndTime + "',"
+ imgArr + ", " + Convert.ToInt16 (AllDay) + ", " + Convert.ToInt16 (AMOnly)
+ ", " + Convert.ToInt16 (PMOnly) + ", '" + DefaultDescript ion.Replace("'" ,
"''")
+ "', '" + DefaultNotes.Re place("'", "''") + "');";
SqlCommand sbCMD = new SqlCommand(sbSQ L, dbConn);
try
{
sbCMD.ExecuteSc alar();
}
But it fails when the query executes, because in my SQL, imgArr has been
replaced by "System.Byt e[]" (i.e. what the "ToString() " method would do)
rather than the array of bytes...
So, I understand why it's doing it, but how do I get around it? Googling
I've seen mention of using command builders and datasets or datatables and
parameters and so on, but it seems like a load more work!
James.
Comment