Results 1 to 4 of 4

Thread: Issue with ExecuteNonQuery on SQL CE

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    3

    Issue with ExecuteNonQuery on SQL CE

    Hi All -
    I am rather new to vb.net using SQL CE. This is using 3.5 framework
    I am trying to use a button to insert records into a table in a SQL CE database.
    rowsaffected returns a value of 1, but when I preview the data, the row is never inserted.

    As I am new at this, I am pretty much lost in what needs to be changed. The sql statement I am using uses hardcoded values only because I am trying to get this to intially work. Once I can get the insert statement to work, it will use variables based on user input.

    Here is my code that I am using:
    -----------------------------------------------------------------------
    Private Sub cmdInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInsert.Click
    Dim connstr As String
    Dim rowsaffected As Integer

    connstr = ("Data Source =" _
    + (System.IO.Path.GetDirectoryName(System.Reflection .Assembly.GetExecutingAssembly.GetName.CodeBase) _
    + ("\jhepfner.sdf;")))

    Dim myconn = New System.Data.SqlServerCe.SqlCeConnection(connstr)

    Dim stringAdd As String = "Insert into t_acct_Taps (acct_num,acct_Tap_key) values (9999,4948)"
    Dim objcommand As New Data.SqlServerCe.SqlCeCommand(stringAdd, myconn)

    Try
    objcommand.Connection.Open()
    rowsaffected = (objcommand.ExecuteNonQuery())
    MsgBox(rowsaffected)
    objcommand.Connection.Close()
    objcommand.Connection.Dispose()
    objcommand = Nothing
    Catch ex As Exception
    MsgBox(ex.ToString)

    End Try
    End Sub
    -----------------------------------------------------------------------
    The original database that I am using is c:\jhepfner.sdf

    When I run this, connstr shows:
    Data Source =\Program Files\jhepfner\jhepfner.sdf;

    In server explorer, it shows the connection string as:
    Data Source=C:\Documents and Settings\Compaq_Owner\Local Settings\Application Data\Temporary Projects\jhepfner\jhepfner.sdf

    Please help, and thank you,
    Jeff

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2010
    Posts
    3

    Re: Issue with ExecuteNonQuery on SQL CE

    Thanks.
    I have read this and haven't quite figured out what the resolution is. Like I mentioned, I am quite new at this and am not sure what I need to do. I understand the concept that it makes a secondary db file, but not quite sure how to set it so it updates the actual .sdf fiile as needed.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Issue with ExecuteNonQuery on SQL CE

    Well, it should be obvious...
    At run time, your file is located here: \Program Files\jhepfner\jhepfner.sdf;
    At design time it is located here: C:\Documents and Settings\Compaq_Owner\Local Settings\Application Data\Temporary Projects\jhepfner\jhepfner.sdf

    Clearly not the same place... so it's no wonder... if you're checkign your database in the server explorer for the data, it's not going to be there because that's not the COPY that you wrote to.

    Also, you may want to read the link in my sig "I swear I saved my data, where'd it run off to?" ... it might help shed some light on this. (or it may not, but at least give it a go and see if it applies).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width