473,503 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing images in SQL Server 2008 through VB.Net 2008

54 New Member
Dear Brothers & Sisters,

Please, I 'm using vb 2008 and I connect it to MS SQL 08. Now, I have a picture field named, "pic" and I want the content of the picture to be saved in the SQL database & retrieved onto the VB form. Below is the code and how to store the pic field indicated in bold below is the problem. The pic field in the database is an image datatype. Please, help me with VB code. Thank you in advance.

Expand|Select|Wrap|Line Numbers
  1. Public Sub SaveCompensationValue()
  2.  
  3.       If frmMain.txtLocation.Text.Trim = "" Then
  4.         frmMain.txtLocation.Focus()
  5.         MsgBox("Location cannot be empty", MsgBoxStyle.Exclamation, "Location")
  6.         Exit Sub
  7.       End If
  8.  
  9.       If frmMain.txtFileNo.Text.Trim = "" Then
  10.         frmMain.txtFileNo.Focus()
  11.         MsgBox("File No. cannot be empty", MsgBoxStyle.Exclamation, "File No.")
  12.         Exit Sub
  13.       End If
  14.       strUsername = GetSetting("Valuation", "Connection", "DataL1")
  15.       strPassword = GetSetting("Valuation", "Connection", "DataL2")
  16.       strServerName = GetSetting("Valuation", "Connection", "DataL3")
  17.       strInitialCatalog = GetSetting("Valuation", "Connection", "DataL4")
  18.       DataL1 = strUsername & strPassword & strServerName & strInitialCatalog
  19.       SQLcon = New SqlConnection
  20.       SQLCom = New SqlCommand
  21.       SQLcon.ConnectionString = DataL1
  22.       Dim SqlQuery As String = "Insert into CompensationValuation (DateOfValuation, ValueOrCost, TotalFloorArea, UnitCostRate, [Floor], Wall, Door, [Windows], [Ceiling], Roof, Location, FileNo, Remarks, pic) " & _
  23.           "Values('" & frmMain.dtDateOfValuation.Text.Trim & "','" & frmMain.txtValue.Text.Trim & "','" & frmMain.txtTotalFloorArea.Text.Trim & "','" & frmMain.txtUnitCostRate.Text.Trim & "','" & frmMain.txtFloor.Text.Trim & _
  24.           "', '" & frmMain.txtWall.Text.Trim & "','" & frmMain.txtDoor.Text.Trim & "','" & frmMain.txtWindows.Text.Trim & "','" & frmMain.txtCeiling.Text.Trim & "','" & frmMain.txtRoof.Text.Trim & _
  25.           "', '" & frmMain.txtLocation.Text.Trim & "','" & frmMain.txtFileNo.Text.Trim & "','" & frmMain.txtRemarks.Text.Trim & "','" & frmMain.pic.Text.Trim & "')" '& "','" & frmMain.txtCeiling.Text.Trim & "','" & frmMain.txtRoof.Text.Trim & _
  26.       SQLCom.Connection = SQLcon
  27.       SQLCom.CommandType = 1
  28.       SQLCom.CommandText = SqlQuery
  29.       Try
  30.         SQLcon.Open()
  31.         Dim strMsg As String = MsgBox("Save data?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Saving confirmation")
  32.         If strMsg = MsgBoxResult.Yes Then
  33.           SQLCom.ExecuteNonQuery()
  34.           MsgBox("Data saved successfully", MsgBoxStyle.Information)
  35.         End If
  36.       Catch
  37.         MsgBox(Err.Description)
  38.       End Try
  39.  
  40.     End Sub
Jun 10 '11 #1
0 1070

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4839
by: Michael Walton | last post by:
I need some help, because I am utterly confused with how to do this. I have 2 things that I need to figure out, and could use some sample code or just some general direction: 1) I need to build...
6
3038
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
9
2351
by: Adam J Knight | last post by:
Hi all, Just wondering whats everyones prefered method of storing images ? 1) File System 2) Database (SqlServer) (Seems to be easier, but has a performance hit) Appreciate some insight!!!...
1
1597
by: steelghost | last post by:
I'm currently trying to store images into my DB. But the collation used on my DB is big5, since my client wants this default encoding on their webpage. So to be able read the retreived data I have...
2
1151
by: Spondishy | last post by:
Hi, I've taken over a publishing application that stores images in a sql server db. The architecture is basically many load balanced web servers connecting to the db. When an image is pulled...
2
1200
by: gomzi | last post by:
hi, I would like to know as to how I could enable write access to one of my folder( on my hosting company's server-shared hosting account) for storing the images. I can't seem to find any way of...
5
5297
by: CAM | last post by:
Hello, I am using SQL Server Express 2008 for my database and Visual Studios 2008 - Visual Basic.Net for my forms. I Gone into VS 2008 and specify the source of data using the Data Sources...
22
34680
MMcCarthy
by: MMcCarthy | last post by:
I have an upcoming project which requires the recording of thumbprint/fingerprint scans in a database (currently proposed as sql server). Now I have a few questions I need to explore: How does...
0
1364
by: kino | last post by:
I am trying to test storing images in a database, I got this code after searching on Google but it doesn't work: protected void Button1_Click(object sender, EventArgs e) { string...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.