Wednesday, June 6, 2007

SQL Compact return new insertion identity

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;
}

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.

This happens when your .sdf database version changed and perhaps corrupted. It might due to merge replication of using SQL Server 2005. Therefore the only solution is to repair it.

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

most of us solve problem as straight away try to do it without thinking or planning when given a problem. This often lead to slow productivity because the method used is not effective enough to solve the a given problem. Perhaps there is a better way solving the problem, you might not know it. Therefore just keep these checklists in mind before starting any problem solving:

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.

User interface is very important to improve the usability of the software. Software application failed to meet user expectations and requirements are often due to the lack of proper UI design. Simple UI often impress user whereas complex UI often frighten user away. When design UI, the first thing have to come to every developer mind; always design in user perspective.

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.

Most often when we write a piece of software we often lack of consideration thanking about designing a fast loading program and this is always true if we designed a small program. Actually there are various of ways to improve the performance of program, for example keep the program initialization as light weight as possible, be careful when we allocate memory, and always think of threaded programming design. Sometimes, we feel demotivated because of the expensive cost involve in having putting performance design in the first place, however, investment will be well worth if the customer don't feel your software is slow and underperformed in average.

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

Normally the default date for sql server is shown as 1/1/2007 12:00:00, however i feel the format of the date is too long and it would be better to be formatted as 1 Jan 2007. In order to create this effect, here the tip.

CONVERT(CHAR(11), getdate(), 106) AS Date