Link to home
Start Free TrialLog in
Avatar of directxBOB
directxBOBFlag for Ireland

asked on

Inserting an image into the database.

I am using Advantage Database v9.

I am trying to insert an image into the database as a blob, and extract it back out as a blob. Right now though it appears to be inserting the image as Memo even though I am putting it in as a Blob.

Any help would really be appreciated as I am  really stuck on this one. I've included the code that I am using so you can get a better idea of exactly what i am doing but I merely followed the tutorials to get this.

My customers application reads out the images as BLOBs, and I don't believe they would be willing to change just for me.

Cheers
 
private void button4_Click(object sender, EventArgs e)
{
    AdsConnection connection = new AdsConnection();
 
    try
    {
	AdsCommand cmd = new AdsCommand();
 
	connection.ConnectionString = Connectionstring;
	connection.Open();
 
	 string sqle = "Select * from callactions WHERE callnumber =146301 ";
			cmd.CommandText = sqle;
			cmd.Connection = connection;
			DataSet testdataset = new DataSet();
			AdsDataAdapter adp = new AdsDataAdapter();
			adp.SelectCommand = cmd;
			adp.Fill(testdataset, "callactions");
 
	string test = testdataset.Tables[0].Columns["signaturegraphic"].DataType.ToString ();
 
	Image anImage = Image.FromFile("C:\\img.bmp");
 
	MemoryStream ms = new MemoryStream();
	anImage.Save(ms, anImage.RawFormat);
	ms.Position = 0;
	byte[] blob = new byte[ms.Length];
	ms.Position = 0;
	ms.Read(blob, 0, Convert.ToInt16(ms.Length));
 
	 sqle = "Insert into rachtest (imageid,image) values (3, :Param )";
      
	 AdsParameter prm = new AdsParameter("Param", DbType.Binary   , blob.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Default, blob);
 
	cmd.Parameters.Add(prm);
	cmd.CommandText = sqle;
	cmd.Connection = connection;
	cmd.ExecuteNonQuery();
 
    }
    catch (Exception ex)
    {
	MessageBox.Show("ERROR" + ex.Message, "ERROR");
    }
    finally
    {
	connection.Close();
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of grant300
grant300

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of directxBOB

ASKER

I'm not really sure if this makes sense, as I don't know how to go into Advantage and extract the SQL for a table (sorry I'm use to SQL Server2005)

So here is what I am doing:

The DB File format is ADT and the datatype on the field is [image].
If i open the database properties of my table within the Advantage data Architect application the datatype is appearing as blob even though this isnt one of the options within the dropdown list.

If i open the table data inside Advantage data Architect  and i double click on the blob field i can see my image straight away as image data but if i save into this table using the code i gave it opens the field as memo data and no image can be seen.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial