Jasmine
Jasmine

Reputation: 5326

How to give a image name as parameter in insert query

I am getting trouble on how to give image name which is selected from the hardcoded value as below.

cmd = new SqlCommand("insert into Images(Image)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;

It throws an exception in line one, and it says

")" incorrect syntax.

I just want to put the value img as in 3rd line to the Images table which has 3 columns viz Id, Name and Image. I want to insert the image(img) into Image column which is of image datatype.

Please help me :(

Upvotes: 3

Views: 694

Answers (1)

John Woo
John Woo

Reputation: 263743

You have an invalid INSERT syntax. try this,

cmd = new SqlCommand("insert into Images([Image]) VALUES (@img)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;

one more thing, img must be byte array.

Upvotes: 6

Related Questions