How to add field contents as name of image.

markh2011

Member
Licensed User
Longtime User
HI,
I am trying to add the contents of an edit field so it is the name of a picture.jpg and then store it in a database.

I want to replace the '1' with the contents of an edit box [edtlocation.text]

B4X:
        Dim InputStream1 As InputStream
     InputStream1 = File.OpenInput(File.DirRootExternal, "1.jpg")     xxxxxxxxxx this is where i want to put the edtLocation.text contents
        Dim OutputStream1 As OutputStream
   OutputStream1.InitializeToBytesArray(1000)
   File.Copy2(InputStream1, OutputStream1)
   Dim Buffer() As Byte
   Buffer = OutputStream1.ToBytesArray

SQL1.ExecNonQuery("INSERT INTO finds VALUES('" & edtDate.text & "','" & edtTime.text & "','" & edtLat.Text & "','" & edtLong.Text & "','" & edtLocation.Text & "','" & edtDepth.Text & "''" & edtWeight.Text & "''" & edtDetect.Text & "','" & edtCoil.Text & "','"Array As Object(Buffer))")

Its not compiling and the error i get is
Error description: Length cannot be less than zero.
Parameter name: length
Occurred on line: 142
SQL1.ExecNonQuery("INSERT INTO finds VALUES('" & edtDate.text & "','" & edtTime.text & "','" & edtLat.Text & "','" & edtLong.Text & "','" & edtLocation.Text & "','" & edtDepth.Text & "''" & edtWeight.Text & "''" & edtDetect.Text & "','" & edtCoil.Text & "','"Array As Object(Buffer))")
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are missing a comma before Array as object and it should be ExecNonQuery2.
There is no need to write such a string. First you can use _ to break the line into multiple lines.
Secondly you should change it to something like:
B4X:
SQL1.ExecNonQuery2("INSERT INTO finds VALUES(?, ?, ?, ?, ?)", _
      Array As Object(edtDate.text.Text, edtTime, ...))
 
Upvote 0

markh2011

Member
Licensed User
Longtime User
Thanks for the info & it now compiles if i comment out the image naming section.
I still need to be able to get the jpg file to use the string in the edtLocation.text so would like advice on how to do that.


When i submit the record will it record the image name in the (buffer) record which is the final part of the SQL1.ExecNonQuery2 [see below]?

SQL1.ExecNonQuery2("INSERT INTO finds VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?,)", _
Array As Object(edtDate.text, edtTime.text, edtLat.text, edtLong.Text, edtLocation.Text, _
edtDepth.Text, edtWeight.Text, edtDetect.Text,edtCoil.Text, Array As Object(Buffer)))
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…