Help me to save image into mssql database

manuaaa

Member
Licensed User
Longtime User
Please help me to save image to ms sql database. the database is available in web server. i am saving data through sql query like.

a.Query("INSERT INTO TAB_DAY_PLANNER (EMPID, Date_ID, DP_DATE, TIME_FROM, TIME_TO, PLANNED_PLACE, PLANNED_INSTITU, PLANNED_WITH, worktype, remark) VALUES("& Password.Text &", 101, '" & datetxt.Text & "', '" & frmbtn.Text & "', '" & tobtn.Text & "', '" & Spinner1.SelectedItem & "', '" & Spinner3.SelectedItem & "', '" & Spinner2.SelectedItem & "', '" & spLanguage.SelectedItem & "', '" & Remark.Text & "' )")

Pl help me to save image.

Thanks
manuaaa
Forward Message
 

michals

Member
Licensed User
Longtime User
I have also noticed that picture saved to mssql database as string encoded with encodebase64 is unreadable and not wroks with desktop app
B4X:
Sub Read_Image(Dir As String, FileName As String) As Byte()
    Dim out As OutputStream
    out.InitializeToBytesArray(100)
    File.Copy2(File.OpenInput(Dir, FileName), out)
    Return out.ToBytesArray
End Sub

Private Sub imagesend
Dim byt() As Byte
       byt = Read_Image(File.DirRootExternal,"/test.png")
       Dim msqlcmd As String
Dim su As StringUtils
msqlcmd = "insert into images(id,img,idtowar) values(21,'" & su.EncodeBase64(byt) & "',1)"

msql.ExecuteNonQuery ( msqlcmd,False)

End Sub

In mssql database this imagelokk different than other images (bad image id=5, images with id's , 1,2,3 are good)

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…