Android Question Struggling with 'Insert'

Anirban Sen

Member
Licensed User
I have a table "BetPosition" where "BetNo" is auto incremented.
I intend to insert records through user interface where information for "odds1", "odds2"..etc comes from text boxes.
I do not know how to write the statement where text boxes values gets updated to the database.
I wrote:
Sql1.ExecNonQuery ("Insert into BetPosition (Odds1, Odds2, Favourite, Amount, BetTeam) values (EditText2.Text, EditText7.Text, EditText6.Text, EditText9.Text, EditText8.Text) ")

which is not working.

Please help with the correct syntax.

Thanks in advance.
 

Attachments

  • BetPosition.JPG
    BetPosition.JPG
    25.8 KB · Views: 436
gets updated
First RULE: INSERT does NOT UPDATE anything

Try it with something like
Code: Copy
Sql1.ExecNonQuery2 ("UPDATE BetPosition SET Odds1=?, Odds2=?, Favourite=?, Amount=?, BetTeam=? WHERE BetNo=?",Array As Object(EditText2.Text, EditText7.Text, EditText6.Text, EditText9.Text, EditText8.Text, idofitem) ")
where idofitem should be replaced with the id of the dataset you want to update. BetNo should replaced by the fieldname of the ID (if it is not BetNo (i used this based on your Screenshot)).

https://www.sqlite.org/lang_insert.html
https://www.sqlite.org/lang_update.html
 
Last edited:
Upvote 0
I am sorry for the confusion. Actually, when I mentioned "updated", I meant the record to be inserted in the database. I am trying to enter a new record. Since BetNo is auto incremented, I need not insert a value for BetNo specifically.
Based on your suggestion, I have modified my INSERT statement as under:
Sql1.ExecNonQuery ("Insert into BetPosition (Odds1=?, Odds2=?, Favourite=?, Amount=?, BetTeam=?) values (EditText2.Text, EditText7.Text, EditText6.Text, EditText9.Text, EditText8.Text) ")
But this is not working.
 

Attachments

Last edited:
Upvote 0
Learn the SQL language.

I posted links to the documentation above. You did not read/understand it

Code: Copy
    Sql1.ExecNonQuery2("Insert into BetPosition SET Odds1=?, Odds2=?, Favourite=?, Amount=?, BetTeam=?",Array As Object(EditText2.Text, EditText7.Text, EditText6.Text, EditText9.Text, EditText8.Text))

For any new question; please create a new Thread
 
Upvote 0
This throws following error:
Caused By : SQL(query) error or missing database.
(near "SET": syntax error (code 1): , while compiling: Insert into BetPosition SET Odds1=?, Odds2=?, Favourite=?, Amount=?, BetTeam=?)

In any case, I will try to read/ understand from the links again. Thanks for your support.
 
Upvote 0
This is working..thank you.
Sql1.ExecNonQuery("Insert into BetPosition (Odds1, Odds2, Favourite, Amount, BetTeam) Values ('"& EditText2.Text &"', '"& EditText7.Text &"', '"& EditText6.Text &"', '"& EditText9.Text &"', '"& EditText8.Text &"')")
 
Upvote 0
Back
Top