Datentyp Image in Sql Server

JKruse

Grünschnabel
Hallo,

ich versuche ein Feld im Sql Server 2005 (Datentyp image) mit einem byte[] (application) zu füllen. Leider schlägt das Ganze mit folgender Meldung fehl:

Excpetion:
"Failed to convert parameter value from a String to a Byte[]."

InnerException:
{"Invalid cast from 'System.String' to 'System.Byte[]'."}


C#-Code:
Code:
this.sqlInsert = "INSERT INTO anwendung (object) " +
                       "VALUES (@Object)";
this.sqlCommand = new SqlCommand(this.sqlInsert, this.sqlConnection);

SqlParameter paramObject;
paramObject = new SqlParameter("@Object", SqlDbType.Image);
paramObject.Value = application;
this.sqlCommand.Parameters.Add(paramObject);

Mein byte[] wird folgenermaßen erstellt:
Code:
private byte[] application;

private void btnSelectApplication_Click(object sender, EventArgs e)
{
  OpenFileDialog openFileDialog = new OpenFileDialog();
  openFileDialog.Filter = "(*.dll)|*.dll";
  if (openFileDialog.ShowDialog() == DialogResult.OK)
  {
    FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open);
    BinaryReader reader = new BinaryReader(fs);
    application = reader.ReadBytes((int)fs.Length);
    reader.Close();
    fs.Close();
  }
}

Kann mir jemand bei dem Problem weiterhelfen?
Die Exception wird beim ExcuteNonQuery geworfen...

Viele Grüße
Jens
 
Zurück