Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 15 total
Thread Inserting image into MEMO column
Fri, Apr 24 2015 8:48 PMPermanent Link

Durendal

Hello,

Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
Mon, Apr 27 2015 4:12 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Something like this should do it:

private byte[] imagebytes;
public Image Portrait;

using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
{
  MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"

  Portrait = new Bitmap("C:\My Images\image001.jpg");

  using (MemoryStream ms = new MemoryStream())
  {
    Portrait.Save(ms, Portrait.RawFormat);
    imagebytes = ms.ToArray();
  }

  MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
  MyCommand.Parameters["ImageFld"].Value = imagebytes;

  MyCommand.ExecuteNonQuery();
}

Chris Holland
[Team Elevate]

On 25/04/2015 01:48, Durendal wrote:
> Hello,
>
> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>
Mon, Apr 27 2015 1:43 PMPermanent Link

Durendal

Thank you, Chris.  I will give this a try.


Chris Holland wrote:

Something like this should do it:

private byte[] imagebytes;
public Image Portrait;

using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
{
  MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"

  Portrait = new Bitmap("C:\My Images\image001.jpg");

  using (MemoryStream ms = new MemoryStream())
  {
    Portrait.Save(ms, Portrait.RawFormat);
    imagebytes = ms.ToArray();
  }

  MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
  MyCommand.Parameters["ImageFld"].Value = imagebytes;

  MyCommand.ExecuteNonQuery();
}

Chris Holland
[Team Elevate]

On 25/04/2015 01:48, Durendal wrote:
> Hello,
>
> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>
Tue, Apr 28 2015 2:58 AMPermanent Link

Durendal

Hi Chris,

Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message

"ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"

                     MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";

                     MyCommand.Parameters.AddWithValue("ID", 3);
                     MyCommand.Parameters.AddWithValue("Name", "Test3");
                     MyCommand.Parameters.Add("Document", OdbcType.Image);
                     MyCommand.Parameters["Document"].Value = imagebytes;

                     MyCommand.ExecuteNonQuery();


Chris Holland wrote:

Something like this should do it:

private byte[] imagebytes;
public Image Portrait;

using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
{
  MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"

  Portrait = new Bitmap("C:\My Images\image001.jpg");

  using (MemoryStream ms = new MemoryStream())
  {
    Portrait.Save(ms, Portrait.RawFormat);
    imagebytes = ms.ToArray();
  }

  MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
  MyCommand.Parameters["ImageFld"].Value = imagebytes;

  MyCommand.ExecuteNonQuery();
}

Chris Holland
[Team Elevate]

On 25/04/2015 01:48, Durendal wrote:
> Hello,
>
> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>
Tue, Apr 28 2015 3:40 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

What type of column is "Document" in the table - in mine I am using
"Graphic"

If you are using a Memo field you may need to change the

MyCommand.Parameters.Add("Document", OdbcType.Image);

to

MyCommand.Parameters.Add("Document", OdbcType.Text);

I have not tested this though.

Chris Holland
[Team Elevate]

On 28/04/2015 07:58, Durendal wrote:
> Hi Chris,
>
> Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message
>
> "ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"
>
>                        MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";
>
>                        MyCommand.Parameters.AddWithValue("ID", 3);
>                        MyCommand.Parameters.AddWithValue("Name", "Test3");
>                        MyCommand.Parameters.Add("Document", OdbcType.Image);
>                        MyCommand.Parameters["Document"].Value = imagebytes;
>
>                        MyCommand.ExecuteNonQuery();
>
>
> Chris Holland wrote:
>
> Something like this should do it:
>
> private byte[] imagebytes;
> public Image Portrait;
>
> using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
> {
>     MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"
>
>     Portrait = new Bitmap("C:\My Images\image001.jpg");
>
>     using (MemoryStream ms = new MemoryStream())
>     {
>       Portrait.Save(ms, Portrait.RawFormat);
>       imagebytes = ms.ToArray();
>     }
>
>     MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
>     MyCommand.Parameters["ImageFld"].Value = imagebytes;
>
>     MyCommand.ExecuteNonQuery();
> }
>
> Chris Holland
> [Team Elevate]
>
> On 25/04/2015 01:48, Durendal wrote:
>> Hello,
>>
>> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>>
>
Tue, Apr 28 2015 3:40 AMPermanent Link

Durendal

Hi Chris,

In one of the older post (http://www.elevatesoft.com/forums?action=view&category=dbisam&id=dbisam_odbc&msg=1794&page=3) you recommend  OdbcType.Text for MEMO column.   Would  OdbcType.Image work as well?  From the error msg, the driver seems to be expected something at the end of the byte[] being passed in.  Thank you.


Durendal wrote:

Hi Chris,

Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message

"ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"

                     MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";

                     MyCommand.Parameters.AddWithValue("ID", 3);
                     MyCommand.Parameters.AddWithValue("Name", "Test3");
                     MyCommand.Parameters.Add("Document", OdbcType.Image);
                     MyCommand.Parameters["Document"].Value = imagebytes;

                     MyCommand.ExecuteNonQuery();


Chris Holland wrote:

Something like this should do it:

private byte[] imagebytes;
public Image Portrait;

using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
{
  MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"

  Portrait = new Bitmap("C:\My Images\image001.jpg");

  using (MemoryStream ms = new MemoryStream())
  {
    Portrait.Save(ms, Portrait.RawFormat);
    imagebytes = ms.ToArray();
  }

  MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
  MyCommand.Parameters["ImageFld"].Value = imagebytes;

  MyCommand.ExecuteNonQuery();
}

Chris Holland
[Team Elevate]

On 25/04/2015 01:48, Durendal wrote:
> Hello,
>
> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>
Tue, Apr 28 2015 5:28 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Hi Durendal,

What is the Data Type for your "Document" column in the table?

Chris Holland
[Team Elevate]

On 28/04/2015 08:40, Durendal wrote:
> Hi Chris,
>
> In one of the older post (http://www.elevatesoft.com/forums?action=view&category=dbisam&id=dbisam_odbc&msg=1794&page=3) you recommend  OdbcType.Text for MEMO column.   Would  OdbcType.Image work as well?  From the error msg, the driver seems to be expected something at the end of the byte[] being passed in.  Thank you.
>
>
> Durendal wrote:
>
> Hi Chris,
>
> Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message
>
> "ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"
>
>                        MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";
>
>                        MyCommand.Parameters.AddWithValue("ID", 3);
>                        MyCommand.Parameters.AddWithValue("Name", "Test3");
>                        MyCommand.Parameters.Add("Document", OdbcType.Image);
>                        MyCommand.Parameters["Document"].Value = imagebytes;
>
>                        MyCommand.ExecuteNonQuery();
>
>
> Chris Holland wrote:
>
> Something like this should do it:
>
> private byte[] imagebytes;
> public Image Portrait;
>
> using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
> {
>     MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"
>
>     Portrait = new Bitmap("C:\My Images\image001.jpg");
>
>     using (MemoryStream ms = new MemoryStream())
>     {
>       Portrait.Save(ms, Portrait.RawFormat);
>       imagebytes = ms.ToArray();
>     }
>
>     MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
>     MyCommand.Parameters["ImageFld"].Value = imagebytes;
>
>     MyCommand.ExecuteNonQuery();
> }
>
> Chris Holland
> [Team Elevate]
>
> On 25/04/2015 01:48, Durendal wrote:
>> Hello,
>>
>> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>>
>
Tue, Apr 28 2015 1:32 PMPermanent Link

Durendal

It is of type MEMO, Chris.  Thank you for looking into this.


Chris Holland wrote:

Hi Durendal,

What is the Data Type for your "Document" column in the table?

Chris Holland
[Team Elevate]

On 28/04/2015 08:40, Durendal wrote:
> Hi Chris,
>
> In one of the older post (http://www.elevatesoft.com/forums?action=view&category=dbisam&id=dbisam_odbc&msg=1794&page=3) you recommend  OdbcType.Text for MEMO column.   Would  OdbcType.Image work as well?  From the error msg, the driver seems to be expected something at the end of the byte[] being passed in.  Thank you.
>
>
> Durendal wrote:
>
> Hi Chris,
>
> Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message
>
> "ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"
>
>                        MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";
>
>                        MyCommand.Parameters.AddWithValue("ID", 3);
>                        MyCommand.Parameters.AddWithValue("Name", "Test3");
>                        MyCommand.Parameters.Add("Document", OdbcType.Image);
>                        MyCommand.Parameters["Document"].Value = imagebytes;
>
>                        MyCommand.ExecuteNonQuery();
>
>
> Chris Holland wrote:
>
> Something like this should do it:
>
> private byte[] imagebytes;
> public Image Portrait;
>
> using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
> {
>     MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"
>
>     Portrait = new Bitmap("C:\My Images\image001.jpg");
>
>     using (MemoryStream ms = new MemoryStream())
>     {
>       Portrait.Save(ms, Portrait.RawFormat);
>       imagebytes = ms.ToArray();
>     }
>
>     MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
>     MyCommand.Parameters["ImageFld"].Value = imagebytes;
>
>     MyCommand.ExecuteNonQuery();
> }
>
> Chris Holland
> [Team Elevate]
>
> On 25/04/2015 01:48, Durendal wrote:
>> Hello,
>>
>> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>>
>
Tue, Apr 28 2015 8:29 PMPermanent Link

Durendal

Hi Chris,

It is of type MEMO, please see the image and the table in the attached zip file.  Thank you.


Chris Holland wrote:

Hi Durendal,

What is the Data Type for your "Document" column in the table?

Chris Holland
[Team Elevate]

On 28/04/2015 08:40, Durendal wrote:
> Hi Chris,
>
> In one of the older post (http://www.elevatesoft.com/forums?action=view&category=dbisam&id=dbisam_odbc&msg=1794&page=3) you recommend  OdbcType.Text for MEMO column.   Would  OdbcType.Image work as well?  From the error msg, the driver seems to be expected something at the end of the byte[] being passed in.  Thank you.
>
>
> Durendal wrote:
>
> Hi Chris,
>
> Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message
>
> "ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"
>
>                        MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";
>
>                        MyCommand.Parameters.AddWithValue("ID", 3);
>                        MyCommand.Parameters.AddWithValue("Name", "Test3");
>                        MyCommand.Parameters.Add("Document", OdbcType.Image);
>                        MyCommand.Parameters["Document"].Value = imagebytes;
>
>                        MyCommand.ExecuteNonQuery();
>
>
> Chris Holland wrote:
>
> Something like this should do it:
>
> private byte[] imagebytes;
> public Image Portrait;
>
> using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
> {
>     MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"
>
>     Portrait = new Bitmap("C:\My Images\image001.jpg");
>
>     using (MemoryStream ms = new MemoryStream())
>     {
>       Portrait.Save(ms, Portrait.RawFormat);
>       imagebytes = ms.ToArray();
>     }
>
>     MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
>     MyCommand.Parameters["ImageFld"].Value = imagebytes;
>
>     MyCommand.ExecuteNonQuery();
> }
>
> Chris Holland
> [Team Elevate]
>
> On 25/04/2015 01:48, Durendal wrote:
>> Hello,
>>
>> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>>
>



Attachments: SampleTable.zip
Wed, Apr 29 2015 6:09 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Hi Durendal,

For MEMO columns you should use this as the definition of the parameter:

MyCommand.Parameters.Add("Document", OdbcType.Text);


Chris Holland
[Team Elevate]

On 29/04/2015 01:29, Durendal wrote:
> Hi Chris,
>
> It is of type MEMO, please see the image and the table in the attached zip file.  Thank you.
>
>
> Chris Holland wrote:
>
> Hi Durendal,
>
> What is the Data Type for your "Document" column in the table?
>
> Chris Holland
> [Team Elevate]
>
> On 28/04/2015 08:40, Durendal wrote:
>> Hi Chris,
>>
>> In one of the older post (http://www.elevatesoft.com/forums?action=view&category=dbisam&id=dbisam_odbc&msg=1794&page=3) you recommend  OdbcType.Text for MEMO column.   Would  OdbcType.Image work as well?  From the error msg, the driver seems to be expected something at the end of the byte[] being passed in.  Thank you.
>>
>>
>> Durendal wrote:
>>
>> Hi Chris,
>>
>> Is there any code needed for the memo column Document below?  Without the Memo column, I am able to add the row.  With the memo column (last column named Document), I got this error message
>>
>> "ERROR [42000] [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL parsing error - Expected NULL, Memo expression but instead found ? in INSERT SQL statement at line 1, column 57"
>>
>>                         MyCommand.CommandText = "INSERT INTO dcdocument2 (ID, Name, Document) VALUES(?,?,?)";
>>
>>                         MyCommand.Parameters.AddWithValue("ID", 3);
>>                         MyCommand.Parameters.AddWithValue("Name", "Test3");
>>                         MyCommand.Parameters.Add("Document", OdbcType.Image);
>>                         MyCommand.Parameters["Document"].Value = imagebytes;
>>
>>                         MyCommand.ExecuteNonQuery();
>>
>>
>> Chris Holland wrote:
>>
>> Something like this should do it:
>>
>> private byte[] imagebytes;
>> public Image Portrait;
>>
>> using (OdbcCommand MyCommand = new OdbcCommand("", Info.Connection))
>> {
>>      MyCommand.CommandText = "INSERT INTO TableName" (ImageFld) VALUES(?)"
>>
>>      Portrait = new Bitmap("C:\My Images\image001.jpg");
>>
>>      using (MemoryStream ms = new MemoryStream())
>>      {
>>        Portrait.Save(ms, Portrait.RawFormat);
>>        imagebytes = ms.ToArray();
>>      }
>>
>>      MyCommand.Parameters.Add("ImageFld", OdbcType.Image);
>>      MyCommand.Parameters["ImageFld"].Value = imagebytes;
>>
>>      MyCommand.ExecuteNonQuery();
>> }
>>
>> Chris Holland
>> [Team Elevate]
>>
>> On 25/04/2015 01:48, Durendal wrote:
>>> Hello,
>>>
>>> Using C#, how do I insert an image from a windows folder (i.e.  C:\My Images\image001.jpg) into a table?  Thank you.
>>>
>>
>
Page 1 of 2Next Page
Jump to Page:  1 2
Image