问题
I have the following script for insertion into a SQL Server CE database
SqlCeConnection Con = new SqlCeConnection();
Con.ConnectionString = (@"Data Source=|DataDirectory|\Database.sdf;Password=Password;");
Con.Open();
SqlCeCommand Query = new SqlCeCommand("INSERT INTO Users(ID,Name,FName,Address,MCode,MNum,Amount) VALUES(@ID,@Name,@FName,@Address,@Code,@Num,@Amount)", Con)
Query.Parameters.AddWithValue("@ID", ID + 1);
Query.Parameters.AddWithValue("@Name", NBox.Text);
Query.Parameters.AddWithValue("@FName", SOBox.Text);
Query.Parameters.AddWithValue("@Address", AdBox.Text);
Query.Parameters.AddWithValue("@Code", Convert.ToInt32(MCode.Text));
Query.Parameters.AddWithValue("@Num", Convert.ToInt32(MNum.Text));
Query.Parameters.AddWithValue("@Amount", Convert.ToInt32(AmBox.Text));
int rowsEffected=Query.ExecuteNonQuery();
MessageBox.Show(rowsEffected.ToString());
After insertion the message box show rows affected=1
this means that data successfully inserted into database I am using VC# 2010 as file copy property moves database file to Debug/Bin/Release
folders and when I check my database file in my project folder it is empty as Bin/Release
file is visible outside the Solution Explorer so I am not able to check it I want to check my DB file for evaluation i-e data is inserted properly in it or not
Kindly tell me how to do this
Thanks!
回答1:
Here's your problem:
... file copy property moves DB file to Debug/Bin/Release Folder and when i check my database file in my project folder it is empty
The database file in your project folder is the original, unchanged source data. When you build your app Visual Studio copies (not moves) the original project file to your output folder (Bin/Release or whatever). Your code inserts the data into the copy, not the original unchanged data.
To "check your DB file for evaluation" you have to check the copy, not the original, unchanged, source file. You can do that either from the same app that inserts the data, from a test app that also uses the DataDirectory
property if it is in the same output folder, or you can open the file in the output directory (Bin/release in your case).
... Bin/Release file is visible outside the Solution explorer ...
Yes, because it is not part of your project. It is output data as if you called Stream.Write
or Console.Writeline
. The original, unchanged source data is part of your source, like your .cs files. It is not delivered to the user or changed by running your app. You have to test the copy in Bin/Release or whatever.
来源:https://stackoverflow.com/questions/11801352/check-sql-server-ce-database-after-insertion-for-application-evaluation