sumitmehta
New Member
- Messages
- 215
- Reaction score
- 1
- Points
- 0
[FONT="]Saving image in ms sql database using asp.net in vb.net code[/FONT]
[FONT="]Hye Guys. I hope this is useful for someone.[/FONT]
[FONT="]Imports[/FONT][FONT="] System.Data.OleDb[/FONT]
[FONT="]Imports[/FONT][FONT="] System.Drawing[/FONT]
[FONT="]Imports[/FONT][FONT="] System.Drawing.Imaging[/FONT]
[FONT="]Partial[/FONT][FONT="] Class RSell[/FONT][FONT="] Inherits System.Web.UI.Page[/FONT]
[FONT="] Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click[/FONT]
[FONT="] Dim len As Integer[/FONT]
[FONT="] Dim len1 As Integer[/FONT]
[FONT="] len = img.PostedFile.ContentLength[/FONT]
[FONT="] len1 = img1.PostedFile.ContentLength[/FONT]
[FONT="] Dim pic(len) As Byte[/FONT]
[FONT="] Dim pic1(len1) As Byte[/FONT]
[FONT="] img.PostedFile.InputStream.Read(pic, 0, len)[/FONT]
[FONT="] img1.PostedFile.InputStream.Read(pic1, 0, len1)[/FONT]
[FONT="] Dim LoginUser As String[/FONT]
[FONT="] Dim UserMid As Integer[/FONT]
[FONT="] Dim midstr As String[/FONT]
[FONT="] Dim sellstr As String[/FONT]
[FONT="] Dim disposal, fireplace, furnished, gasrange, microwave, washer, balcony, water, carparking As String[/FONT]
[FONT="] Dim sellcon As OleDbConnection[/FONT]
[FONT="] Dim sellcmd As OleDbCommand[/FONT]
[FONT="] Dim midcmd As OleDbCommand[/FONT]
[FONT="] Dim midread As OleDbDataReader[/FONT]
[FONT="] LoginUser = Session("Username")[/FONT]
[FONT="] If chkDesp.Checked = True Then[/FONT]
[FONT="] disposal = "yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] disposal = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkFirePlace.Checked = True Then[/FONT]
[FONT="] fireplace = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] fireplace = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkFurnished.Checked = True Then[/FONT]
[FONT="] furnished = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] furnished = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkGasRange.Checked = True Then[/FONT]
[FONT="] gasrange = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] gasrange = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkMicrowave.Checked = True Then[/FONT]
[FONT="] microwave = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] microwave = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkWasher.Checked = True Then[/FONT]
[FONT="] washer = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] washer = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkBalcony.Checked = True Then[/FONT]
[FONT="] balcony = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] balcony = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkWater.Checked = True Then[/FONT]
[FONT="] water = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] water = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] If chkParking.Checked = True Then[/FONT]
[FONT="] carparking = "Yes"[/FONT]
[FONT="] Else[/FONT]
[FONT="] carparking = "No"[/FONT]
[FONT="] End If[/FONT]
[FONT="] sellcon = New OleDbConnection("Provider=SQLOLEDB;Data Source=pml;Initial Catalog=property;Integrated Security=SSPI")[/FONT]
[FONT="] midstr = "select mid from master where username='" & LoginUser & "'"[/FONT]
[FONT="] midcmd = New OleDbCommand(midstr, sellcon)[/FONT]
[FONT="] sellcon.Open()[/FONT]
[FONT="] midread = midcmd.ExecuteReader[/FONT]
[FONT="] While (midread.Read)[/FONT]
[FONT="] UserMid = Integer.Parse(midread("mid"))[/FONT]
[FONT="] End While[/FONT]
[FONT="] Session("Usermid") = UserMid[/FONT]
[FONT="] sellstr = "insert into sell(mid,categories,type,country,state,city,area,pincode,bedroom,bathroom,psize,tsize,price,description,hospital,airport,railway,school,tvphone,paints,ac,motot,lift,rainwater,disposal,fireplace,furnished,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 & "',?,? )"[/FONT]
[FONT="] sellcmd = New OleDbCommand(sellstr, sellcon)[/FONT]
[FONT="] sellcmd.Parameters.Add("@im", pic)[/FONT]
[FONT="] sellcmd.Parameters.Add("@im1", pic1)[/FONT]
[FONT="] sellcmd.ExecuteNonQuery()[/FONT]
[FONT="] sellcon.Close()[/FONT]
[FONT="] Response.Redirect("SSSell.aspx")[/FONT]
[FONT="] End Sub[/FONT]
[FONT="]End[/FONT][FONT="] Class
I will post SSell.aspx code in another thread. The thread would be named as 'Uploading image in ms sql database'
[/FONT]