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.
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.
Code:
Public Sub SaveCompensationValue() If frmMain.txtLocation.Text.Trim = "" Then frmMain.txtLocation.Focus() MsgBox("Location cannot be empty", MsgBoxStyle.Exclamation, "Location") Exit Sub End If If frmMain.txtFileNo.Text.Trim = "" Then frmMain.txtFileNo.Focus() MsgBox("File No. cannot be empty", MsgBoxStyle.Exclamation, "File No.") Exit Sub End If strUsername = GetSetting("Valuation", "Connection", "DataL1") strPassword = GetSetting("Valuation", "Connection", "DataL2") strServerName = GetSetting("Valuation", "Connection", "DataL3") strInitialCatalog = GetSetting("Valuation", "Connection", "DataL4") DataL1 = strUsername & strPassword & strServerName & strInitialCatalog SQLcon = New SqlConnection SQLCom = New SqlCommand SQLcon.ConnectionString = DataL1 Dim SqlQuery As String = "Insert into CompensationValuation (DateOfValuation, ValueOrCost, TotalFloorArea, UnitCostRate, [Floor], Wall, Door, [Windows], [Ceiling], Roof, Location, FileNo, Remarks, pic) " & _ "Values('" & frmMain.dtDateOfValuation.Text.Trim & "','" & frmMain.txtValue.Text.Trim & "','" & frmMain.txtTotalFloorArea.Text.Trim & "','" & frmMain.txtUnitCostRate.Text.Trim & "','" & frmMain.txtFloor.Text.Trim & _ "', '" & frmMain.txtWall.Text.Trim & "','" & frmMain.txtDoor.Text.Trim & "','" & frmMain.txtWindows.Text.Trim & "','" & frmMain.txtCeiling.Text.Trim & "','" & frmMain.txtRoof.Text.Trim & _ "', '" & frmMain.txtLocation.Text.Trim & "','" & frmMain.txtFileNo.Text.Trim & "','" & frmMain.txtRemarks.Text.Trim & "','" & frmMain.pic.Text.Trim & "')" '& "','" & frmMain.txtCeiling.Text.Trim & "','" & frmMain.txtRoof.Text.Trim & _ SQLCom.Connection = SQLcon SQLCom.CommandType = 1 SQLCom.CommandText = SqlQuery Try SQLcon.Open() Dim strMsg As String = MsgBox("Save data?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Saving confirmation") If strMsg = MsgBoxResult.Yes Then SQLCom.ExecuteNonQuery() MsgBox("Data saved successfully", MsgBoxStyle.Information) End If Catch MsgBox(Err.Description) End Try End Sub