Try this code it will help.
public Int64 AddCustomer(string LastName, string FirstName, int?
AddressID, string MembershipUsername, string PhoneNumber, string
MobilePhoneNumber)
{
SQLCeHelper sqlce = new
SQLCeHelper(Properties.Settings.Default.CarServ3DB4ConnectionString);
string
queryString =
"INSERT INTO Customer" +
"(LastName, FirstName, AddressID,
MembershipUsername, PhoneNumber, MobilePhoneNumber)" +
"VALUES
(@LastName,@FirstName,@AddressID,@MembershipUsername,@PhoneNumber,@MobilePhoneNumber)";
Int64
newIdentity = 0;
using (SqlCeConnection connection = new
SqlCeConnection(
Properties.Settings.Default.CarServ3DB4ConnectionString))
{
SqlCeCommand
command = new SqlCeCommand(queryString,
connection);
command.Connection.Open();
command.Parameters.Add("@LastName",
LastName);
command.Parameters.Add("@FirstName",
FirstName);
command.Parameters.Add("@AddressID", (object)AddressID??
DBNull.Value );
command.Parameters.Add("@MembershipUsername",
MembershipUsername);
command.Parameters.Add("@PhoneNumber",
PhoneNumber);
command.Parameters.Add("@MobilePhoneNumber",
MobilePhoneNumber);
command.ExecuteNonQuery();
SqlCeCommand command1 = new
SqlCeCommand("select @@identity ", connection);
newIdentity =
Convert.ToInt32(command1.ExecuteScalar());
}
return
newIdentity;
}
Wednesday, June 6, 2007
SQL Compact return new insertion identity
Thursday, May 31, 2007
FileNotFoundException was unhandled
Could not load file or assembly 'System.Data.SqlServerCe, Version=9.0.242.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies.
The system cannot find the file specified.
You might encountered this error when the System.Data.SqlServerCe version has redirected to another newer version due Visual Studio 2005 generated code on your application config file.
To solve this problem, you have to delete something like below in you app.config file.
xmlns="urn:schemas-microsoft-com:asm.v1"> name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91"
culture="neutral"/>newVersion="9.0.242.0"/>
hope this helps
Saturday, May 26, 2007
You are trying to access an older version of a SQL Server Compact Edition database. If this is a SQL Server CE 1.0 or 2.0 database, run upgrade.exe.
To repair it you must use the
System.Data.SqlServerCe.SqlCeEngine class, version 9.0.242.0 or 3.5.0.0
Here is the example of the implementation.
File.Copy(@"F:\northwind.sdf",@"F:\northwind.sdf.temp");
File.Delete(@"F:\northwind.sdf");
SqlCeEngine
engine = new SqlCeEngine(@"Data Source
=F:northwind.sdf.temp");
engine.Compact(@"Data
Source=F:\northwind.sdf");
File.Delete(@"F:\northwind.sdf.temp");
A repaired northwind.sdf is produced and now you should not be getting this error again. Any other alternative? Please let me know. :)
Friday, May 25, 2007
Before trying to solve, think first
Do your research and gather as much information as you can.
Any question, don't wait... ask Google.
Give yourself various alternative solutions.
Be creative and don't afraid to break the rules.
If you could follow all these mention above, you could be a better problem solver.
Wednesday, May 23, 2007
software user interface design.
A great UI must always have these criteria:
simple and does the job right.
good navigation and proper UI arrangement
easy accessible functions and customized menu for the user
fast and responsive UI
please keep in mind that UI design is the first user impression of the software.
Thursday, April 5, 2007
Keep application performance design in first place.
Assume that we design a small program called Sales Reporting to be used in an organization. Since the program has just only a few modules, we ignore the performance design. Over the time, we might be adding some functionality, hence the complexity of the program increase. Maintainability of the program also an issue if the program is not well designed. One day, you are requested to improve the performance of the program because users are keep complaining that the slow loading program keep them not be patient anymore. Users are fed up and their work is always distracted. The company are not going to invest to redesigned the program because over the year many time and money was spent in maintaining the program. The program is reliable and the problem is just lack of performance. You as a software consultant is hired to perform this task, what is the first thing you would do?
You might be run test the program at the first place to see which area need to be improved. You had identify that some areas need to be redesigned for significant performance gain. You had just planned the initial strategy. Secondly, you are looking to the source code, you are over surprise that most part of the code could be very difficult to be modify for performance gain because the original designer do not keep the best practise in coding hence lead to performance issue. Another concern is that the application is extremely tedious to convert to threaded application because initially the program is very difficult to maintain and the structure the application is not well understood by anyone.
You see, the scenario above has demonstrated that application tend to be extremely difficult to gain performance when the application aged. To solve this problem we must keep performance design in the first place during application planning and design phase.
Wednesday, April 4, 2007
Format default date in SQL Server 2005
CONVERT(CHAR(11), getdate(), 106) AS Date