There is a problem with the "Generate Insert Script"
function when it comes to columns that are of DateTime
type.
The current output is based on the current culture
So on my machine, one example date would be:
15.11.2005 10:08:46 (November 15th 2005)
But when I run the query, the DB interpretes this as
the 11th of the 15th month and gives and overflow error.
The format of the date needs to be in an unambigous
format.
This is easily accomplished by using the ToString("s")
method on datetime instead of the generic ToString()
I made the following changes to DataManager.cs in the
namespace QueryCommander.Database.Microsoft.Sql2000.
I changed
else if(dt.Columns[i].DataType ==
System.Type.GetType("System.String") ||
dt.Columns[i].DataType ==
System.Type.GetType("System.DateTime") )
valueString += "'" +
row.ItemArray[i].ToString().Replace("'","''") + "', ";
to
else if(dt.Columns[i].DataType ==
System.Type.GetType("System.String") )
valueString += "'" +
row.ItemArray[i].ToString().Replace("'","''") + "', ";
else if(dt.Columns[i].DataType ==
System.Type.GetType("System.DateTime"))
valueString += "'" + ((DateTime)
row.ItemArray[i]).ToString("s") + "', ";
And this fixed it.
Jan Obrestad
obrestad@rocketmail.com