locked
SQL Insert command not working RRS feed

  • Question

  • trying to add records with the insert command but not working.  No errors just no new records either.  What am i doing wrong?

     

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim conn As SqlCeConnection = Nothing

            Dim mpg As Integer

            Dim pth As String = (Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetName.CodeBase))

            pth = pth & "\dogs.sdf"

            Dim dte As String

                conn = New SqlCeConnection("Data Source = " & pth)

                Dim cmd As SqlCeCommand = conn.CreateCommand()

                conn.Open()

               cmd.CommandText = "INSERT INTO mytable (weight) VALUES(55)"

                cmd.ExecuteNonQuery()

            conn.Close()

        End Sub

     

    Friday, May 7, 2010 10:57 PM

Answers

  • It is stored at the location which is in variable 'pth' inside emulator. To access emulator file system cradle it and then use WMDC to browse just like you would with real device. To view data copy database to your desktop and open it as usual.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Rjl66 Tuesday, May 11, 2010 12:12 PM
    Monday, May 10, 2010 6:28 AM

All replies

  • Why do you believe it's not working? You're not checking original (and unchanged) database copy on your desktop but changed copy on your device, correct?
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, May 9, 2010 6:29 AM
  • This is in the debugger,  I have not yet deployed to my device.  

    When I run the same syntax in the query builder it adds the records to my database but when run thru the attached code just does nothing.

    Let me try deploying to my phone and seeing if that works.  This is my first database attempt, not sure of the differences between debugger and actual installed program.

     

     

    Sunday, May 9, 2010 2:11 PM
  • Do you mean emulator?

    That does not answer my question. How do you know this does nothing? Please describe in details how do you check record was not added to the database.

    In any case please make sure you're checking against database which was actually changed (on your device or emulator), not unchanged copy on your desktop.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, May 9, 2010 4:48 PM
  • Yes the emulator.   While in the emulator I refresh my datagrid but no added records.

     

    Also in the server explorer, i right click on my table and show table data.  Still nothing

    Am i looking in the wrong place?

     

    Sunday, May 9, 2010 10:47 PM
  • Yes, you're looking in a wrong place. Emulator is a simulated device, it has it's own simulated storage which contains changed copy of the database.

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, May 10, 2010 1:26 AM
  • Can you tell me where it's stored and how to view it?

     

    Thanks

     

    Monday, May 10, 2010 2:50 AM
  • It is stored at the location which is in variable 'pth' inside emulator. To access emulator file system cradle it and then use WMDC to browse just like you would with real device. To view data copy database to your desktop and open it as usual.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Rjl66 Tuesday, May 11, 2010 12:12 PM
    Monday, May 10, 2010 6:28 AM
  • Thanks Ilya,

    You're suspicions were correct,  I was updating the table the whole time, just looking in the wrong place.

     

    Tuesday, May 11, 2010 12:13 PM