1

I am developing a system. I usually add data in the database by coding it using visual studio 2013, for example:

Select * from tbl_login where loginID = '" & TextBox1.Text & "'

It works with strings, but not with an image. I don't know what should I use to save an image from a PictureBox.

Also, what is better? Using IMAGE or VARBINARY(MAX) as datatype?

Thanks in advance!

2
  • 1
    SQL Injection alert - you should not concatenate together your SQL statements - use parametrized queries instead to avoid SQL injection Commented Oct 31, 2016 at 5:25
  • 1
    ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. See details here Commented Oct 31, 2016 at 5:25

3 Answers 3

4

My advice is to not to save an image into the database. Instead you could save path of the image and store the actual image somewhere in the server. Because saving image data may make database size high.

If you are restricted to save image data into the database, you can choose varbinary(max). The datatype IMAGE is deprecated. So avoid using IMAGE datatype. You need to convert Image data into Binary format through your scripting language and need to store into the database.

Another advice is dont use appending type query building from front end like

  Select * from tbl_login where loginID = '" & TextBox1.Text & "'

There may be a chance of attack through SQL Injection.

Sign up to request clarification or add additional context in comments.

2 Comments

can i still retrieve the image even if it's just the path that is being saved?
yes.. You need to call image with path just like html anchor tag. You will find more about asp.net in web.
1

Another good solution is to use File Tables, which enables the user to gain the best of both worlds. Ex- Non-transnational streaming access and in-place updates to files. Access the files in a hierarchical structure (similar to file system). Ability to store and query file attributes such as created date. Compatibility with Windows file and directory management APIs. Compatibility with other SQL Server features.

Comments

0

The simplest way to download the dll from the site https://vbsqlconn.blogspot.com/

Its very easy to use.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.