Member Avatar for සශික

I'm just trying to insert some more informations to mysql table. I used recently methods. But it won't help me. so if you can help me ?
my code is below :

Try
            Dim mstream1 As New System.IO.MemoryStream()
            Add_House.pic1.Image.Save(mstream1, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage1() As Byte = mstream1.GetBuffer()
            mstream1.Close()

            Dim mstream2 As New System.IO.MemoryStream()
            Add_House.pic2.Image.Save(mstream2, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage2() As Byte = mstream2.GetBuffer()
            mstream2.Close()

            Dim mstream3 As New System.IO.MemoryStream()
            Add_House.pic3.Image.Save(mstream3, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage3() As Byte = mstream3.GetBuffer()
            mstream3.Close()

            Dim mstream4 As New System.IO.MemoryStream()
            Add_House.pic4.Image.Save(mstream4, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage4() As Byte = mstream4.GetBuffer()
            mstream4.Close()

            Dim Ceiling_Type As String
            If Add_House.RadioButton1.Checked = True Then
                Ceiling_Type = "Suspention"
            ElseIf Add_House.RadioButton2.Checked = True Then
                Ceiling_Type = "Exposed Rafter"
            End If

            Dim Ceiling_Sub_Type As String
            If Add_House.RadioButton1.Checked = True Then
                Ceiling_Sub_Type = (Add_House.cmbhsuspentiontype.Text)
            ElseIf Add_House.RadioButton2.Checked = True Then
                Ceiling_Sub_Type = (Add_House.cmbhexposedtype.Text)
            End If

            query = "INSERT INTO brokerage.house(Serial_NO, House_Category, House_Size, Land_Extent, Floor_Type, Tiled_Area, Ceiling, Full_AC, Roof, Balcony, Terrace, Address, City, District, Plan_NO, Deed_NO, Price, Description, Pic_1, Pic_2, Pic_3, Pic_4, NO_of_Bed_Rooms, NO_of_AC_Rooms, NO_of_NonAC_Rooms, Attached_Bathroom_Availability, NO_of_Attached_Bathroom, NO_of_Tiled_Rooms, Kitchen_Availability, Pantry_Availability, NO_of_Pantry, Ceiling_Availability, Ceiling_Type, Ceiling_Sub_Type, Landscape, Boundary_Wall, Gate_Availability, Coverage_Parking, Open_Parking, Road_Side_Parking, Driver_Room_Availability, Is_Driver_Room_With_Bathroom, Mate_Room_Availability, Is_Mate_Room_With_Bathroom, Other_Rooms_Description, Electricity_Type, NO_of_Lights, Plug_Points_5amp, Plug_Points_15amp, NO_of_FANs, Water_Type, Underground_Sump_Availability, Capacity_of_Underground_Sump, OH_Tank_Availability, Capacity_of_OH_Tank, Preasure_Pump_Availability, Coate_Water_Availability, Coate_Water_Type, CCTV_Availability, Gated_Community_Availability, Owner_Name, Owner_Address, Owner_NIC, Owner_Contact, Broker_Name, Broker_Address, Broker_NIC, Broker_Contact)" & _
                    "VALUES (@Serial_NO, @House_Category, @House_Size, @Land_Extent, @Floor_Type, @Tiled_Area, @Ceiling, @Full_AC, @Roof, @Balcony, @Terrace, @Address, @City, @District, @Plan_NO, @Deed_NO, @Price, @Description, @Pic_1, @Pic_2, @Pic_3, @Pic_4, @NO_of_Bed_Rooms, @NO_of_AC_Rooms, @NO_of_NonAC_Rooms, @Attached_Bathroom_Availability, @NO_of_Attached_Bathroom, @NO_of_Tiled_Rooms, @Kitchen_Availability, @Pantry_Availability, @NO_of_Pantry, @Ceiling_Availability, @Ceiling_Type, @Ceiling_Sub_Type, @Landscape, @Boundary_Wall, @Gate_Availability, @Coverage_Parking, @Open_Parking, @Road_Side_Parking, @Driver_Room_Availability, @Is_Driver_Room_With_Bathroom, @Mate_Room_Availability, @Is_Mate_Room_With_Bathroom, @Other_Rooms_Description, @Electricity_Type, @NO_of_Lights, @Plug_Points_5amp, @Plug_Points_15amp, @NO_of_FANs, @Water_Type, @Underground_Sump_Availability, @Capacity_of_Underground_Sump, @OH_Tank_Availability, @Capacity_of_OH_Tank, @Preasure_Pump_Availability, @Coate_Water_Availability, @Coate_Water_Type, @CCTV_Availability, @Gated_Community_Availability, @Owner_Name, @Owner_Address, @Owner_NIC, @Owner_Contact, @Broker_Name, @Broker_Address, @Broker_NIC, @Broker_Contact)"

            Dim cmd As MySqlCommand = New MySqlCommand(query, con)
            cmd.Parameters.AddWithValue("@Serial_NO", Convert.ToInt64(Add_House.txthserialno.Text))
            cmd.Parameters.AddWithValue("@House_Category", Convert.ToString(Add_House.cmbhcategory.Text))
            cmd.Parameters.AddWithValue("@House_Size", Convert.ToString(Add_House.txthsize.Text))
            cmd.Parameters.AddWithValue("@Land_Extent", Convert.ToString(Add_House.txtlandextent.Text))
            cmd.Parameters.AddWithValue("@Floor_Type", Convert.ToString(Add_House.cmbhfloortype.Text))
            cmd.Parameters.AddWithValue("@Tiled_Area", Convert.ToString(Add_House.txthtiledarea.Text))
            cmd.Parameters.AddWithValue("@Ceiling", Convert.ToString(Add_House.cmbhceiling.Text))
            cmd.Parameters.AddWithValue("@Full_AC", Convert.ToString(Add_House.cmbhfullac.Text))
            cmd.Parameters.AddWithValue("@Roof", Convert.ToString(Add_House.cmbhroof.Text))
            cmd.Parameters.AddWithValue("@Balcony", Convert.ToString(Add_House.cmbhbalcony.Text))
            cmd.Parameters.AddWithValue("@Terrace", Convert.ToString(Add_House.cmbhterrace.Text))
            cmd.Parameters.AddWithValue("@Address", Convert.ToString(Add_House.txthaddress.Text))
            cmd.Parameters.AddWithValue("@City", Convert.ToString(Add_House.txthcity.Text))
            cmd.Parameters.AddWithValue("@District", Convert.ToString(Add_House.cmbhdistrict.Text))
            cmd.Parameters.AddWithValue("@Plan_NO", Convert.ToString(Add_House.txthplanno.Text))
            cmd.Parameters.AddWithValue("@Deed_NO", Convert.ToString(Add_House.txthdeedno.Text))
            cmd.Parameters.AddWithValue("@Price", Convert.ToString(Add_House.txthprice.Text))
            cmd.Parameters.AddWithValue("@Description", Convert.ToString(Add_House.txthdescription.Text))
            cmd.Parameters.AddWithValue("@Pic_1", arrImage1)
            cmd.Parameters.AddWithValue("@Pic_2", arrImage2)
            cmd.Parameters.AddWithValue("@Pic_3", arrImage3)
            cmd.Parameters.AddWithValue("@Pic_4", arrImage4)
            cmd.Parameters.AddWithValue("@NO_of_Bed_Rooms", Convert.ToString(Add_House.txthnoofbedrooms.Text))
            cmd.Parameters.AddWithValue("@NO_of_AC_Rooms", Convert.ToString(Add_House.txthnoofac.Text))
            cmd.Parameters.AddWithValue("@NO_of_NonAC_Rooms", Convert.ToString(Add_House.txthnoofnonac.Text))
            cmd.Parameters.AddWithValue("@Attached_Bathroom_Availability", Convert.ToString(Add_House.cmbhattachedbathroom.Text))
            cmd.Parameters.AddWithValue("@NO_of_Attached_Bathroom", Convert.ToString(Add_House.txthattachednoofbathrooms.Text))
            cmd.Parameters.AddWithValue("@NO_of_Tiled_Rooms", Convert.ToString(Add_House.txthnooftiledrooms.Text))
            cmd.Parameters.AddWithValue("@Kitchen_Availability", Convert.ToString(Add_House.cmbhkitchenavailability.Text))
            cmd.Parameters.AddWithValue("@Pantry_Availability", Convert.ToString(Add_House.cmbhpantryavailability.Text))
            cmd.Parameters.AddWithValue("@NO_of_Pantry", Convert.ToString(Add_House.txthnoofpantry.Text))
            cmd.Parameters.AddWithValue("@Ceiling_Availability", Convert.ToString(Add_House.cmbhceilingavailability.Text))
            cmd.Parameters.AddWithValue("@Ceiling_Type", Convert.ToString(Ceiling_Type))
            cmd.Parameters.AddWithValue("@Ceiling_Sub_Type", Convert.ToString(Ceiling_Sub_Type))
            cmd.Parameters.AddWithValue("@Landscape", Convert.ToString(Add_House.cmbhlandscape.Text))
            cmd.Parameters.AddWithValue("@Boundary_Wall", Convert.ToString(Add_House.cmbhboundarywall.Text))
            cmd.Parameters.AddWithValue("@Gate_Availability", Convert.ToString(Add_House.cmbhgate.Text))
            cmd.Parameters.AddWithValue("@Coverage_Parking", Convert.ToString(Add_House.cmbhcovered.Text))
            cmd.Parameters.AddWithValue("@Open_Parking", Convert.ToString(Add_House.cmbhopen.Text))
            cmd.Parameters.AddWithValue("@Road_Side_Parking", Convert.ToString(Add_House.cmbhroadside.Text))
            cmd.Parameters.AddWithValue("@Driver_Room_Availability", Convert.ToString(Add_House.cmbhdriverq.Text))
            cmd.Parameters.AddWithValue("@Is_Driver_Room_With_Bathroom", Convert.ToString(Add_House.cmbhnoofbathroomdriver.Text))
            cmd.Parameters.AddWithValue("@Mate_Room_Availability", Convert.ToString(Add_House.cmbhmateq.Text))
            cmd.Parameters.AddWithValue("@Is_Mate_Room_With_Bathroom", Convert.ToString(Add_House.cmbhnoofbathroommate.Text))
            cmd.Parameters.AddWithValue("@Other_Rooms_Description", Convert.ToString(Add_House.txthotherroom.Text))
            cmd.Parameters.AddWithValue("@Electricity_Type", Convert.ToString(Add_House.cmbhelectricitytype.Text))
            cmd.Parameters.AddWithValue("@NO_of_Lights", Convert.ToString(Add_House.txthlights.Text))
            cmd.Parameters.AddWithValue("@Plug_Points_5amp", Convert.ToString(Add_House.txth5amp.Text))
            cmd.Parameters.AddWithValue("@Plug_Points_15amp", Convert.ToString(Add_House.txth15amp.Text))
            cmd.Parameters.AddWithValue("@NO_of_FANs", Convert.ToString(Add_House.txthfans.Text))
            cmd.Parameters.AddWithValue("@Water_Type", Convert.ToString(Add_House.cmbhwatertype.Text))
            cmd.Parameters.AddWithValue("@Underground_Sump_Availability", Convert.ToString(Add_House.cmbhundergroundsump.Text))
            cmd.Parameters.AddWithValue("@Capacity_of_Underground_Sump", Convert.ToString(Add_House.txthundergroundsumpcapacity.Text))
            cmd.Parameters.AddWithValue("@OH_Tank_Availability", Convert.ToString(Add_House.cmbhohtank.Text))
            cmd.Parameters.AddWithValue("@Capacity_of_OH_Tank", Convert.ToString(Add_House.txthohtankcapacity.Text))
            cmd.Parameters.AddWithValue("@Preasure_Pump_Availability", Convert.ToString(Add_House.cmbhpreasurepump.Text))
            cmd.Parameters.AddWithValue("@Coate_Water_Availability", Convert.ToString(Add_House.cmbhcoatewater.Text))
            cmd.Parameters.AddWithValue("@Coate_Water_Type", Convert.ToString(Add_House.cmbhcoatewatertype.Text))
            cmd.Parameters.AddWithValue("@CCTV_Availability", Convert.ToString(Add_House.cmbhcctvavailability.Text))
            cmd.Parameters.AddWithValue("@Gated_Community_Availability", Convert.ToString(Add_House.cmbhgatedcommunity.Text))
            cmd.Parameters.AddWithValue("@Owner_Name", Convert.ToString(txthownername.Text))
            cmd.Parameters.AddWithValue("@Owner_Address", Convert.ToString(txthowneraddress.Text))
            cmd.Parameters.AddWithValue("@Owner_NIC", Convert.ToString(txthownernic.Text))
            cmd.Parameters.AddWithValue("@Owner_Contact", Convert.ToString(txthownercontact.Text))
            cmd.Parameters.AddWithValue("@Broker_Name", Convert.ToString(txthbrokername.Text))
            cmd.Parameters.AddWithValue("@Broker_Address", Convert.ToString(txthbrokeraddress.Text))
            cmd.Parameters.AddWithValue("@Broker_NIC", Convert.ToString(txthbrokernic.Text))
            cmd.Parameters.AddWithValue("@Broker_Contact", Convert.ToString(txthbrokercontact.Text))
            Try
                con.Open()
                cmd.ExecuteNonQuery()
                MessageBox.Show("House Added Sucsessfully !", "Save House")
                Add_House.Button5.Enabled = True
                Add_House.homeclear()
                con.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Add_House.Button5.Enabled = True
            End Try
                If (con.State = ConnectionState.Open) Then
                    con.Close()
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            con.Close()
            Add_House.Button5.Enabled = True
            End Try
        Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Add_House.Button5.Enabled = True
        End Try
        land_h_no2()
        Add_House.Button5.Enabled = True
        Me.Close()

When I run this code it give me > "Input string was not in correct format"
When if we turn to database side....
serial_no was integer type
pic_1,pic_2,pic_3,pic_3 were longblob type
all others were varchar.

In your SQL statement there should be a space required before quatation mark. It should be

 Broker_Contact) " & _
                    "VALUES (@Serial_NO,

Do not understand why you are using multiple Try EndTry at a time. a single use of Try EndTry is sufficient.

Member Avatar for සශික

it doesn't help sir, when I again click on add button, that time succcessfully inserted.

Well what I've found out in my code when got the same error was that the formated cells is a bit sensitive to the data entered, so the best way to track when/where exactly the error occures you need to add a MsgBox("Number_here") above each and every code that will be fired so that you will see which part is producing an error. In my case the problem was that I formated the cell to varcha for the date and when I try to enter the date I don't really know what was the problem but I change the way I retrieve/get today's date and it worked if I make it to Shortdate.

In short, there maybe a data that might be in an incorrect format or has some extra charectors not really sure but try evaulate which part of code is producing this error and change the way your data is formated for that part.

I my opinion, the problem arises when you try to use a byte array to fill a parameter without specifying the parameter type
because the default costructor may decide thet the longblob is equivalent to longtext and then translate to string.

please see this discussion about when to use the new AddWithValue or the old Add to explicily specify the SQL type of parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.