Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have Converted my database from access to sql. So while Saving image it throws this error. How can I solve this,

This is my code,

VB
SelStr = "" &
             "Update Admission Set AdmissionNo = '" & AdmNo & "', ENClass = '" & Enclass & "', StudentFN = '" & SFN & "', " &
             "StudentMN = '" & SMN & "', StudentLN = '" & SLN & "', FatherFN = '" & FFN & "', FatherMN = '" & FMN & "', " &
             "FatherLN = '" & FLN & "', MotherFN = '" & MFN & "', MotherMN = '" & MMN & "', MotherLN = '" & MLN & "', " &
             "GuardianFN = '" & GFN & "', GuardianLN = '" & GLN & "', GRelation = '" & GRel & "', CCity = '" & CCity & "', " &
             "FatMob = '" & FathMo & "', AltNo = '" & AltNo & "', Gender =  '" & Gender & "', Category = '" & Category & "', " &
             "Religion = '" & Religion & "', PSName = '" & PSName & "', PSClass = '" & PSClass & "', PSGrade = '" & PSGrade & "', " &
             "PSCity = '" & PSCity & "', PSState = '" & PSState & "', PSPYear = '" & PSYear & "', AddressPer = '" & AddPer & "', " &
             "AddressPre = '" & AddPre & "', Remark = '" & Remark & "', DOB = '" & DOB & "', JnDt = '" & JnDt & "', " &
             "FOcc = '" & Focc & "', FEdu = '" & FEdu & "', FASal = '" & FASal & "', MOcc ='" & MOcc & "', MEdu = '" & MEdu & "', " &
             "MASal = '" & MASal & "', BusFacility = '" & BusFac & "', BusFrmID=0 , BusFrm = 'NA', " &
             "BroSis = '" & BroSis & "', Attachments = '" & AttachLis & "', AttachmentIDs = '" & AttIDs & "', MotMob = '" & MothMo & "', " &
             "[Cast] = '" & SCast & "', SMSNo = '" & SMSNo & "',Student_Images=" & strImage & ",SType = '" & SType & "',Email = '" & Email & "',Aadhar = '" & Aadhar & "' Where AdmissionID = " & temp & ""


       cmd.CommandText = SelStr
       If strImage = "?" Then
           cmd.Parameters.Add(strImage, SqlDbType.Image).Value = arrImage
       End If
       cmd.ExecuteNonQuery()
Posted

1 solution

The main problem is that you concatenate the values directly to the SQL statement. Instead use SqlParameter[^] to stay safe from SQL injections, conversion problems etc.

In other words the code should look something like the following (just few parameters added as an example)
VB
SelStr = "Update Admission Set AdmissionNo = @AdmNo, ENClass = @ENClass, ..."
cmd.CommandText = SelStr
cmd.Parameters.AddWithValue("@AdmNo", AdmNo)
cmd.Parameters.AddWithValue("@ENClass", ENClass)
...


Another thing is that you set the value of Student_Images to ?. Based on the later code the value of strImage can be a question mark, but this is hardly what you're supposed to add to the database column. Just guessing but should the value of Student_Images be arrImage
 
Share this answer
 
v4
Comments
CPallini 7-Sep-15 12:28pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900