|
-
May 15th, 2010, 12:56 PM
#1
Thread Starter
New Member
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
-
May 15th, 2010, 01:13 PM
#2
Frenzied Member
Re: Issue with ExecuteNonQuery on SQL CE
-
May 15th, 2010, 02:41 PM
#3
Thread Starter
New Member
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.
-
May 15th, 2010, 06:52 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|