UPDATED QUESTION:
Ok, I am going to simplify my question since I don’t really know how to answer your questions.
Say I create a new Windows Forms Application,
then Project->Add New Item->Local Database.
Then in Database Explorer I create a table (“testtable”) and give it an “ID” column and “VALUE” column.
Can you provide me with the steps to simply add a row to the database from the code?
OLD QUESTION:
I have been trying to do something
that I think would be really easy but
have never used C# before and am
having trouble with the details. I
simple want to use a sql database with
Visual C# Express 2008.For testing purposes I have a datagrid
on my form that can reflect changes to
the db.If i use this:
codesTableAdapter.Fill(dataSet1.codes);The datagrid(dataset) will fill with
the info from the sql database.If i then do something like this:
codesTableAdapter.InsertQuery(txtCode.Text,txtName.Text); codesTableAdapter.Fill(dataSet1.codes); codesTableAdapter.Update(dataSet1); dataSet1.AcceptChanges();The datagrid reflects the changes but
if close the program and go to the
database the changes are not there.
When I open the program again the
changes are not there.I have a feeling this isn’t too clear
as my understanding here is very low
so please let me know what other info
is needed.
Really hard to understand what is going on without seeing your code, but I will make some guesses:
This will create an empty SQL Server Compact Edition .SDF file in your project. You can edit this file from Visual Studio or SQL CE Query Analyzer.
This will create an empty table in your .SDF file. Those are pretty bad names, but for test purpose we can use them.
System.Data.SqlServerCeprovides methods to manage .SDF files. To add a row to your test table:Be aware that
Path\To\Your\SDF\file.sdfmay not be what your think; Visual Studio by default copies project files to the Project Build Output Path (e.g. Path\to\your\project\bin\Debug\file.sdf). If you change the built file then rebuild your project, the original .SDF file gets recopied to your output path, wiping out any changes you have made to your project file. If that’s not what you want you will have to explain what you are trying to accomplish.For example, to make changes apply only to the built project file, change your data file “Copy to Output Directory” property in VS to “Copy if Newer”.