Insert byte array into SQLServer

I have the following problem:

I have a file which I need to insert into the database in a binary field (Image field is also a possibilty, but the file I need to insert is not an image) through a plain query with C#.

At the moment I got this:
INSERT INTO table(ID,File) VALUES('{0}','{1}');

where 0 is a Unique Identifier and 1, the binary data. But that isnt working, because it is giving me back errors. What am I doing wrong/is the correct syntax?

Ps. I can use either a byte[] or a memorystream for the data, but I prefer a byte[].
LVL 14
Who is Participating?
NazermohideeenConnect With a Mentor Commented:

private int SaveToDB(string imgName, byte[] imgbin)
SqlConnection connection = new SqlConnection(yourConnectionString);
SqlCommand command = new SqlCommand( "INSERT INTO yourTable (img_name,img_data) VALUES ( @img_name, @img_data)", connection );

SqlParameter param0 = new SqlParameter( "@img_name", SqlDbType.VarChar,50 );
param0.Value = imgName;
command.Parameters.Add( param0 );

SqlParameter param1 = new SqlParameter( "@img_data", SqlDbType.Image );
param1.Value = imgbin;
command.Parameters.Add( param1 );

int numRowsAffected = command.ExecuteNonQuery();

return numRowsAffected;

existenz2Author Commented:
Not exactly what I was hoping for, but it solved my problem. Could have known that I should fix it this way ;) Thnx
All Courses

From novice to tech pro — start learning today.