Saving image in ms sql database using asp.net in vb.net code
Hye Guys. I hope this is useful for someone.
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Drawing.Imaging
Partial Class RSell Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim len As Integer
Dim len1 As Integer
len = img.PostedFile.ContentLength
len1 = img1.PostedFile.ContentLength
Dim pic(len) As Byte
Dim pic1(len1) As Byte
img.PostedFile.InputStream.Read(pic, 0, len)
img1.PostedFile.InputStream.Read(pic1, 0, len1)
Dim LoginUser As String
Dim UserMid As Integer
Dim midstr As String
Dim sellstr As String
Dim disposal, fireplace, furnished, gasrange, microwave, washer, balcony, water, carparking As String
Dim sellcon As OleDbConnection
Dim sellcmd As OleDbCommand
Dim midcmd As OleDbCommand
Dim midread As OleDbDataReader
LoginUser = Session("Username")
If chkDesp.Checked = True Then
disposal = "yes"
Else
disposal = "No"
End If
If chkFirePlace.Checked = True Then
fireplace = "Yes"
Else
fireplace = "No"
End If
If chkFurnished.Checked = True Then
furnished = "Yes"
Else
furnished = "No"
End If
If chkGasRange.Checked = True Then
gasrange = "Yes"
Else
gasrange = "No"
End If
If chkMicrowave.Checked = True Then
microwave = "Yes"
Else
microwave = "No"
End If
If chkWasher.Checked = True Then
washer = "Yes"
Else
washer = "No"
End If
If chkBalcony.Checked = True Then
balcony = "Yes"
Else
balcony = "No"
End If
If chkWater.Checked = True Then
water = "Yes"
Else
water = "No"
End If
If chkParking.Checked = True Then
carparking = "Yes"
Else
carparking = "No"
End If
sellcon = New OleDbConnection("Provider=SQLOLEDB;Data Source=pml;Initial Catalog=property;Integrated Security=SSPI")
midstr = "select mid from master where username='" & LoginUser & "'"
midcmd = New OleDbCommand(midstr, sellcon)
sellcon.Open()
midread = midcmd.ExecuteReader
While (midread.Read)
UserMid = Integer.Parse(midread("mid"))
End While
Session("Usermid") = UserMid
sellstr = "insert into sell(mid,categories,type,country,state,city,area,p incode,bedroom,bathroom,psize,tsize,price,descript ion,hospital,airport,railway,school,tvphone,paints ,ac,motot,lift,rainwater,disposal,fireplace,furnis hed,gasrange,microwave,washer,facing,balcony,water ,pcar,img,img1) values (" & UserMid & ",'" & cboCate.SelectedItem.Text & "','" & cboType.SelectedItem.Text & "','" & cboCountry.SelectedItem.Text & "','" & cboState.SelectedItem.Text & "','" & cboCity.SelectedItem.Text & "','" & txtArea.Text & "','" & txtPincode.Text & "','" & cboBedroom.SelectedItem.Text & "','" & cboBathroom.SelectedItem.Text & "','" & txtSize.Text & "','" & cboSize.SelectedItem.Text & "','" & cboPrice.SelectedItem.Text & "','" & txtDescription.Text & "','" & txtHospital.Text & "','" & txtAirPort.Text & "','" & txtRailway.Text & "','" & txtSchool.Text & "','" & txtTv.Text & "','" & txtPaints.Text & "','" & txtAc.Text & "','" & txtMotor.Text & "','" & txtLift.Text & "','" & txtRainwater.Text & "','" & disposal & "','" & fireplace & "','" & furnished & "','" & gasrange & "','" & microwave & "','" & washer & "','" & cboFacing.SelectedItem.Text & "','" & balcony & "','" & water & "','" & carparking & "',?,? )"
sellcmd = New OleDbCommand(sellstr, sellcon)
sellcmd.Parameters.Add("@im", pic)
sellcmd.Parameters.Add("@im1", pic1)
sellcmd.ExecuteNonQuery()
sellcon.Close()
Response.Redirect("SSSell.aspx")
End Sub
End Class
I will post SSell.aspx code in another thread. The thread would be named as 'Uploading image in ms sql database'


LinkBack URL
About LinkBacks
Reply With Quote


