Hi
I can take a photo , also can research on galery and get into my Panel or İmageview.
But my problem is how I can insert into my sqlite database by ID. When I say ADD I want to entry
I have blob column which is 'Resim'. And I also can read from table in my persons.db
I can add text views,
Names
LastNames
And
Photo
I can take a photo , also can research on galery and get into my Panel or İmageview.
But my problem is how I can insert into my sqlite database by ID. When I say ADD I want to entry
I have blob column which is 'Resim'. And I also can read from table in my persons.db
I can add text views,
Names
LastNames
And
Photo
B4X:
Sub AddEntry
Dim Query As String
Dim Cursor1 As Cursor
Dim ID As Int
'SelectedCinsiyet = spnCinsiyet.SelectedIndex
'first we check if the entry already does exist DİKKAT => BİRÇOK kez AND koymayı unuttum aralarına
Query = "SELECT * FROM persons INNER JOIN body ON persons.ID = body.IDbody WHERE persons.ID = body.IDbody AND FirstName = ? AND LastName = ? AND Sex = ? AND BirthDay = ? AND BirthCity = ? AND FatherName = ? AND Boy = ? AND Resim = ?"
Cursor1 = Activity2.SQL1.ExecQuery2(Query, Array As String (edtFirstName.Text, edtLastName.Text, spnCinsiyet.SelectedItem, edtBirthDay.Text, edtBirthCity.Text, edtFatherName.Text, edtBoy.Text))
If Cursor1.RowCount > 0 Then
'if it exists show a message and do nothing else
ToastMessageShow("This entry already exists", False)
Else
'if not, add the entry
'a NULL for the ID column increments the primary key automatically by one
'we use ExecNonQuery2 because it's easier, we don't need to take care of the data types
Query = "INSERT INTO persons VALUES (NULL, ?, ?, ?, ?, ?, ?, NULL)"
Activity2.SQL1.ExecNonQuery2(Query, Array As String(edtFirstName.Text, edtLastName.Text, spnCinsiyet.SelectedItem, edtBirthDay.Text, edtBirthCity.Text, edtFatherName.Text))
Query = "INSERT INTO body VALUES (NULL, NULL, ?, NULL, NULL)"
Activity2.SQL1.ExecNonQuery2(Query, Array As String(edtBoy.Text))
'OutputStream.InitializeToBytesArray
Dim OutputStream1 As OutputStream
Dim Buffer() As Byte 'declares an empty array
OutputStream1 = Panel2.Tag
OutputStream1.InitializeToBytesArray(1000)
'Panel2.SetBackgroundImage()
Buffer = OutputStream1.ToBytesArray
Activity2.SQL1.ExecNonQuery2("INSERT INTO persons VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL,?)",(Array As Object (Buffer)))
ToastMessageShow("Entry added", False) ' confirmation for the user
'to display the ID of the last entry we read the max value of the ID column
ID = Activity2.SQL1.ExecQuerySingleResult("SELECT max(ID) FROM persons")
Activity2.RowNumber = Activity2.RowNumber + 1 'increase the row count
Activity2.IDList.Add(ID) 'add the last ID to the list
Activity2.CurrentIndex = Activity2.IDList.Size - 1 'set the current index to the last one
edtID.Text = ID 'display the last index
End If
Cursor1.Close 'close the cursor, we don't it anymore
ShowButtons
End Sub