I am trying to INSERT into an SQL database table, but it doesn't work. So I used the SQL server profiler to see how it was building the query; what it shows is the following:
declare @p1 int
set @p1=0
declare @p2 int
set @p2=0
declare @p3 int
set @p3=1
exec InsertProcedureName @ConsumerMovingDetailID=@p1 output, @UniqueID=@p2 output,
@ServiceID=@p3 output, @ProjectID=N'0', @IPAddress=N'66.229.112.168',
@FirstName=N'Mike', @LastName=N'P', @Email=N'
[email protected]',
@PhoneNumber=N'(254)637-1256', @MobilePhone=NULL, @CurrentAddress=N'',
@FromZip=N'10005', @MoveInAddress=N'', @ToZip=N'33067',
@MovingSize=N'1', @MovingDate=''2009-04-30 00:00:00:000'',
/* Problem here ^^^ */
@IsMovingVehicle=0, @IsPackingRequired=0, @IncludeInSaveologyPlanner=1
select @p1, @p2, @p3
As you can see, it puts a double quote two pairs of single quotes around the datetime fields, so that it produces a syntax error in SQL.
I wonder if there is anything I must configure somewhere?
Any help would be appreciated.
Here is the environment details:
Visual Studio 2008
.NET 3.5
MS SQL Server
2005
Here is the .NET code I'm using....
//call procedure for results
strStoredProcedureName = "usp_SMMoverSearchResult_SELECT";
Database database = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = database.GetStoredProcCommand(strStoredProcedureName);
dbCommand.CommandTimeout = DataHelper.CONNECTION_TIMEOUT;
database.AddInParameter(dbCommand, "@MovingDetailID", DbType.String, objPropConsumer.ConsumerMovingDetailID);
database.AddInParameter(dbCommand, "@FromZip", DbType.String, objPropConsumer.FromZipCode);
database.AddInParameter(dbCommand, "@ToZip", DbType.String, objPropConsumer.ToZipCode);
database.AddInParameter(dbCommand, "@MovingDate", DbType.DateTime, objPropConsumer.MoveDate);
database.AddInParameter(dbCommand, "@PLServiceID", DbType.Int32, objPropConsumer.ServiceID);
database.AddInParameter(dbCommand, "@FromAreaCode", DbType.String, pFromAreaCode);
database.AddInParameter(dbCommand, "@FromState", DbType.String, pFromState);
database.AddInParameter(dbCommand, "@ToAreaCode", DbType.String, pToAreaCode);
database.AddInParameter(dbCommand, "@ToState", DbType.String, pToState);
DataSet dstSearchResult = new DataSet("MoverSearchResult");
database.LoadDataSet(dbCommand, dstSearchResult, new string[] { "MoverSearchResult" });