none
Basic4ppc and SQLite Insert doesnt work RRS feed

  • Question

  • Im programming in windows mobile 2003, with pocket pc, and what im doing is trying to insert a row in a table, but the code doesn't show any error, the cmd(command).ExecuteNonQuery returns 1, but it doesn't insert anything, what am i doing wrong? this is my code.

    Sub sig_Click

    cmd.AddParameter("sinigas")
    cmd.AddParameter("privados")
    cmd.AddParameter("estado")
    cmd.AddParameter("peso")
    cmd.AddParameter("observaciones")
    cmd.SetParameter("sinigas" ,sinigas.Item(sinigas.SelectedIndex))
    cmd.SetParameter("privados" ,privados.Text)
    cmd.SetParameter("estado" ,peso.Text)
    cmd.SetParameter("peso" ,status.SelectedIndex + 1)
    cmd.SetParameter("observaciones" ,obs.Text)


    Con.BeginTransaction
    cmd.CommandText = "INSERT INTO nuevoinventario(siniga, privado, estado, peso, observaciones)" & _
    "VALUES(@sinigas,@privados,@estado,@peso,@observaciones)"
    cmd.ExecuteNonQuery
    Con.EndTransaction
    End Sub

    cmd is command, con y the conection, 

    Wednesday, July 9, 2014 11:03 PM

Answers

  • I found the problem, it was the weird open and close conections, i start another project and i make it simple, and it WORKED! so, from then i started to put my code and now it works perfectly, it is weird because its practically identical but in the prevous project it doesnt work, anyway, what i can say is, make it simple, make sure it works, and go slowly putting the code, i didnt knew what the problem was, i just know that make another one, and copy paste it worked for me.
    • Marked as answer by joselazcano Friday, July 11, 2014 8:49 PM
    Friday, July 11, 2014 8:49 PM

All replies

  • Hi,

    Please refer to the similar thread.

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/8fc508c6-f31e-44d8-93f5-8a75439dafb3/how-can-i-add-parameter-to-insert-command-in-vbnet-code?forum=vbgeneral

    What's more, please read this document http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx

    For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, July 11, 2014 9:02 AM
    Moderator
  • How do you know nothing was inserted?

    One rather common mistake developers do is checking original copy of the database on the desktop for changes (while device actually works with a _copy_ of that database located on the device). Perhaps that's what is going on? Do check the actual database on the device instead to verify.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, July 11, 2014 3:50 PM
    Moderator
  • Because i have sqlite browser and when i end the app it doesnt show what i inserted, and when i run it again, the results of the selects im doing give me nothing.
    Friday, July 11, 2014 8:47 PM
  • I found the problem, it was the weird open and close conections, i start another project and i make it simple, and it WORKED! so, from then i started to put my code and now it works perfectly, it is weird because its practically identical but in the prevous project it doesnt work, anyway, what i can say is, make it simple, make sure it works, and go slowly putting the code, i didnt knew what the problem was, i just know that make another one, and copy paste it worked for me.
    • Marked as answer by joselazcano Friday, July 11, 2014 8:49 PM
    Friday, July 11, 2014 8:49 PM