?
Solved

insert into blob with C#

Posted on 2006-05-12
5
Medium Priority
?
1,018 Views
Last Modified: 2012-06-27
This is my code:
            flname = "001";
            fldname = "Attachment";

            System.IO.FileStream fs = new System.IO.FileStream(@"D:/Btech/btech_NL/" + flname +".HTM", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
            byte[] rawData = br.ReadBytes((int)fs.Length);
            br.Close();
            fs.Close();

            OdbcCommand cm;
            string query = "INSERT INTO ItemAttachments (ItemCode,ReleaseID) VALUES ('"+ flname +"','11111111-1111-1111-1111-111111111111')";
            cm = new OdbcCommand(query, conn);
            cm.Parameters.Add("", OdbcType.Binary, rawData.Length, fldname).Value = rawData;
            cm.ExecuteNonQuery();

When i debug the code it works perfect. I see a new record in the table, but the field Attachment is empty or null.
The database column Attachment is an Image type.
Any ideas how come?
0
Comment
Question by:secuteamers
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16665985
Unless I am missing something you are adding the binary field to your insert statement?
try
            string query = "INSERT INTO ItemAttachments (ItemCode,ReleaseID, @Binary) VALUES ('"+ flname +"','11111111-1111-1111-1111-111111111111')";
            cm = new OdbcCommand(query, conn);
            cm.Parameters.Add("@Binary", OdbcType.Binary, rawData.Length, fldname).Value = rawData;
0
 

Author Comment

by:secuteamers
ID: 16666110
now i get this error:
 ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '@Binary'
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16666466
Sorry wrong way around...

string query = "INSERT INTO ItemAttachments (ItemCode,ReleaseID, BinaryField) VALUES ('"+ flname +"','11111111-1111-1111-1111-111111111111', @Binary)";
0
 

Author Comment

by:secuteamers
ID: 16666508
getting error:
Must declare variable @Binary.
I'm almost there. Im pretty new at C#.
0
 
LVL 15

Accepted Solution

by:
GavinMannion earned 1500 total points
ID: 16667385
Try changing
cm.Parameters.Add("@Binary", OdbcType.Binary, rawData.Length, fldname).Value = rawData;
to
cm.Parameters.Add("Binary", OdbcType.Binary, rawData.Length, fldname).Value = rawData;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question