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!

William Taylor
  • 691
  • 8
  • 23
ABCDE
  • 131
  • 3
  • 6
  • 15
  • 1
    [SQL Injection alert](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - you should **not** concatenate together your SQL statements - use **parametrized queries** instead to avoid SQL injection – marc_s Oct 31 '16 at 05: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](http://msdn.microsoft.com/en-us/library/ms187993.aspx) – marc_s Oct 31 '16 at 05:25

3 Answers3

3

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.

Shakeer Mirza
  • 5,054
  • 2
  • 18
  • 41
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.

0

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

Its very easy to use.

Naveed
  • 59
  • 2
  • 13