473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to manually generate a SQL statement (SQLCommand) containing binary data ?

How can I manually generate a SQL statement (SQLCommand) containing binary
data ?
I'd like to write all the text of the SQL statement for that operation...

Example :
I Have Binary data (that represent an image)

Byte[] TmpByte;
TmpByte = ....BINARY DATA OF AN IMAGE....

Now I want to generate the SQL statement
to insert the content of TmpByte into
MYTABLE ( MyIndex = VARCHAR(25) / MyData = VARBINARY (1000) )

Something like that :
INSERT MYTABLE (MyIndex, MyData) VALUES ('Index 1', ???? )

But I don't know how to put in place of the ????
I was expecting that someting like '01010101....101001' could work but it
didn't.

Thank for any help !

Steph.
Jun 1 '06 #1
5 2569

TheSteph wrote:
How can I manually generate a SQL statement (SQLCommand) containing binary
data ?


Short answer: use parameters.

Just say if you need the long version...

--
Larry Lard
Replies to group please

Jun 1 '06 #2
Hi,

You have to use a SqlCommand, I use the code below to add a file to the DB

SqlCommand com = new SqlCommand();
com.CommandText = "SaveDocument";
com.CommandType = CommandType.StoredProcedure;
SqlParameter param = com.Parameters.Add("@data", SqlDbType.Image);
//Read the file into memory
FileStream file = new FileStream( physicalname, FileMode.Open);
byte[] buff = new byte [ file.Length];
file.Read(buff, 0, Convert.ToInt32(file.Length));
file.Close();
param.Value = buff;
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"TheSteph" <Th******@NoSpam.com> wrote in message
news:OV**************@TK2MSFTNGP05.phx.gbl...
How can I manually generate a SQL statement (SQLCommand) containing binary
data ?
I'd like to write all the text of the SQL statement for that operation...

Example :
I Have Binary data (that represent an image)

Byte[] TmpByte;
TmpByte = ....BINARY DATA OF AN IMAGE....

Now I want to generate the SQL statement
to insert the content of TmpByte into
MYTABLE ( MyIndex = VARCHAR(25) / MyData = VARBINARY (1000) )

Something like that :
INSERT MYTABLE (MyIndex, MyData) VALUES ('Index 1', ???? )

But I don't know how to put in place of the ????
I was expecting that someting like '01010101....101001' could work but it
didn't.

Thank for any help !

Steph.

Jun 1 '06 #3
For larger binary (where the byte[] becomes an overhead), see also my
self-answered post titled "Writing BLOBs (through C#)" from a few minutes
ago...

Marc
Jun 1 '06 #4
Hi,
"Marc Gravell" <ma**********@gmail.com> wrote in message
news:u1**************@TK2MSFTNGP02.phx.gbl...
For larger binary (where the byte[] becomes an overhead), see also my
self-answered post titled "Writing BLOBs (through C#)" from a few minutes
ago...


Nice piece of code, will keep it around :)

Thanks


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jun 1 '06 #5
THANKS !!

That's what I was looking for ;-))

Steph.
"Marc Gravell" <ma**********@gmail.com> wrote in message
news:u1**************@TK2MSFTNGP02.phx.gbl...
For larger binary (where the byte[] becomes an overhead), see also my
self-answered post titled "Writing BLOBs (through C#)" from a few minutes
ago...

Marc

Jun 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Hall | last post by:
We need to read a SQL database containing a mix of English words and Chinese Characters. We think we need to use the N'xxxx' to read the Unicode. We have one place where the SELECT statement...
2
by: Grant Stanley | last post by:
I'm writing a database client program in C#, and it accesses a MS SQL V7 database. In one part of my program I am using a SqlCommand class to run a SQL Statement, the command text uses parameters,...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
1
by: dabuskol | last post by:
Hi, I'm trying to run an insert statement continously for 24 hrs, data is coming from different Ip/PORT (100). Could somebody please help me by checking my codes if there's any way I can do to...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
6
by: Manuel Canas | last post by:
Hello there, This is my SQL Insert Statement to insert a single into a table on a database; INSERT tb_test VALUES(' & _ txtTest1.Text & "' " & _ txtTest2.Text & "' " & _ txtPrice.Text & "')"
1
by: job | last post by:
how is it possible to serialize/de-serialize a SqlCommand?
2
by: SFM | last post by:
I just want a simple datareader, that i can read the value returned from a select statement executed on a SQL server 2005 db. The code below should work in, but email= rdr.ToString(); when i...
6
by: Frank Hauptlorenz | last post by:
Hello, I'm trying to send an SqlCommand to a WCF-Service. For this I'm using the following DataContract: public class SqlCommandComposite { SqlCommand cmd = new SqlCommand();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.