Anirban Sen Member Licensed User Apr 26, 2018 #1 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 25.8 KB · Views: 436
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.
DonManfred Expert Licensed User Longtime User Apr 26, 2018 #2 Anirban Sen said: gets updated Click to expand... 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: Apr 26, 2018 Upvote 0
Anirban Sen said: gets updated Click to expand... 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
Anirban Sen Member Licensed User Apr 26, 2018 #3 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 Mithun-Betting.zip Mithun-Betting.zip 172.4 KB · Views: 399 Last edited: Apr 26, 2018 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.
DonManfred Expert Licensed User Longtime User Apr 26, 2018 #4 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
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
Anirban Sen Member Licensed User Apr 26, 2018 #5 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 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.
Anirban Sen Member Licensed User Apr 26, 2018 #6 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
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 &"')")
DonManfred Expert Licensed User Longtime User Apr 26, 2018 #7 Anirban Sen said: This is working.. Click to expand... Great you got it sorted I fear the problem was my sql knowledge which is based on MySQL. Upvote 0
Anirban Sen said: This is working.. Click to expand... Great you got it sorted I fear the problem was my sql knowledge which is based on MySQL.