0

in databse tabel i have fieild with type varbinary(max) for storing image,
so i achieved it and stored my image but the problem is that when i use this line

SqlParameter p8 = new SqlParameter("logo", SqlDbType.VarBinary).Value= productImage;

then it gives me an error but when i use this line :

 com.Parameters.Add("@logo", SqlDbType.VarBinary).Value = productImage;

then it works , WHY ??????

NoteL i am using asp.net 3.5 + sql server 2008 , and using SP to execute it which i achieved but confused about the problem above. HELP !

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by HunainHafeez
1

I dont have experience with storing images in a DB, but the first question is are you sure that you want to go down this path? Depending on the number images, your database will grow quite large. Is there a reason not to simply store the path to the image in a table?

In the first line you are attempting to create an object of type sqlParameter, while in the second line you are simple adding the value of productImage to the parameters property of the SQL command object.

The use of paramters is the preferred method. You should have a sql statement in your code that references that parameter called @logo.

This goes back to some of your other threads where you have tried to use the querystring directly with the sql statement. The use of parameters is one more layer of security for your application.

Votes + Comments
ok jorgem i changed my way of storing images , i am now storing a path only
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.