我有一个Windows窗体应用程序,其中有许多值已成功写入我的数据库。它使用DataSet
和所有常用的自动生成的表适配器等。我没有摆弄任何这些。我只是将我的字段从DataSources选项卡拖放到我的表单上。自动生成的SQL看起来很正常。
我有两个DateTimePicker
控件数据以相同的方式绑定,如果我使用默认值,它们都不会写入数据库。 SQL Server中的数据格式是datetime。
从表单加载方法我正在设置这样的初始日期值。
// Set the Date entered to Today
dateTimePickerDateEntered.Value = DateTime.Now;
// Set the call back date to Today + 7 days
dateTimePickerCallBackDate.Value = DateTime.Now.AddDays(7);
如果我使用datetimepicker控件手动更改日期,则会成功保存到数据库。我确实谷歌这个问题,并找到了解决方案,提出了我已经在做的事情。
默认值在屏幕上看起来不错,如果我今天真的选择,它似乎没有改变。
我应该采取哪些不同的想法?
由于 大卫
我使用默认日期执行了保存,并使用名为SQL Profile Express的工具从服务器捕获生成的sql。
执行了三个命令。
exec sp_resetConnection
exec sp_executesql Insert
exec sp_executesql更新
我不确定为什么要进行更新。它似乎试图更新现有的无关记录,我正在插入一条新记录。 主键文件QuoteID是一个标识字段。
这是插入
`exec sp_executesql N'INSERT INTO [Quote] ([DateEntered], [ContactName], [PreparedFor], [MailAddress1], [MailAddress2], [MASuburb], [MAState], [MAPcode], [SPNumber], [SPAddress1], [SPAddress2], [SPSuburb], [SPState], [SPPcode], [NumberOfUnits], [PricePerUnit], [TotalAnnualFee], [Stationary], [ContactPhoneW], [ContactPhoneH], [ContactPhoneM], [Fax], [Email], [WhyChooseUs], [CurrentlyManagedBy], [DateSent], [CallBackDate], [StatusId], [DocumentLink], [EnteredBy], [PictureLocation]) VALUES (@DateEntered, @ContactName, @PreparedFor, @MailAddress1, @MailAddress2, @MASuburb, @MAState, @MAPcode, @SPNumber, @SPAddress1, @SPAddress2, @SPSuburb, @SPState, @SPPcode, @NumberOfUnits, @PricePerUnit, @TotalAnnualFee, @Stationary, @ContactPhoneW, @ContactPhoneH, @ContactPhoneM, @Fax, @Email, @WhyChooseUs, @CurrentlyManagedBy, @DateSent, @CallBackDate, @StatusId, @DocumentLink, @EnteredBy, @PictureLocation);
SELECT QuoteId, DateEntered, ContactName, PreparedFor, MailAddress1, MailAddress2, MASuburb, MAState, MAPcode, SPNumber, SPAddress1, SPAddress2, SPSuburb, SPState, SPPcode, NumberOfUnits, PricePerUnit, TotalAnnualFee, Stationary, ContactPhoneW, ContactPhoneH, ContactPhoneM, Fax, Email, WhyChooseUs, CurrentlyManagedBy, DateSent, CallBackDate, StatusId, DocumentLink, EnteredBy, PictureLocation FROM Quote WHERE (QuoteId = SCOPE_IDENTITY())',N'@DateEntered datetime,@ContactName char(9),@PreparedFor char(9),@MailAddress1 char(16),@MailAddress2 char(16),@MASuburb char(19),@MAState char(3),@MAPcode char(4),@SPNumber char(6),@SPAddress1 char(18),@SPAddress2 char(18),@SPSuburb char(13),@SPState char(2),@SPPcode char(4),@NumberOfUnits int,@PricePerUnit money,@TotalAnnualFee money,@Stationary money,@ContactPhoneW char(12),@ContactPhoneH char(12),@ContactPhoneM char(12),@Fax char(12),@Email char(19),@WhyChooseUs char(13),@CurrentlyManagedBy char(20),@DateSent datetime,@CallBackDate datetime,@StatusId int,@DocumentLink char(8000),@EnteredBy char(8000),@PictureLocation varchar(63)',@DateEntered=NULL,@ContactName='Joe Smith',@PreparedFor='Bob Jones',@MailAddress1='MAIL ADDRESS ONE',@MailAddress2='MAIL ADDRESS TWO',@MASuburb='MAIL ADDRESS SUBURB',@MAState='NSW',@MAPcode='2000',@SPNumber='123456',@SPAddress1='STRATA ADDRESS ONE',@SPAddress2='STRATA ADDRESS TWO',@SPSuburb='STRATA SUBURB',@SPState='SA',@SPPcode='2001',@NumberOfUnits=100,@PricePerUnit=200.0000,@TotalAnnualFee=20000.0000,@Stationary=3000.0000,@ContactPhoneW='01 123456789',@ContactPhoneH='02 123456789',@ContactPhoneM='03 123456789',@Fax='04 123456789',@Email='my@emailaddress.com',@WhyChooseUs='WHY CHOOSE US',@CurrentlyManagedBy='CURRENTLY MANAGED BY',@DateSent=NULL,@CallBackDate=NULL,@StatusId=NULL,@DocumentLink=NULL,@EnteredBy=NULL,@PictureLocation='C:\Temp\QuoteMasterPlus\Photos\STRATAADDRESSONESTRATASUBURB.jpg'
go`
这是更新
exec sp_executesql N'UPDATE [Quote] SET [DateEntered] = @DateEntered, [ContactName] = @ContactName, [PreparedFor] = @PreparedFor, [MailAddress1] = @MailAddress1, [MailAddress2] = @MailAddress2, [MASuburb] = @MASuburb, [MAState] = @MAState, [MAPcode] = @MAPcode, [SPNumber] = @SPNumber, [SPAddress1] = @SPAddress1, [SPAddress2] = @SPAddress2, [SPSuburb] = @SPSuburb, [SPState] = @SPState, [SPPcode] = @SPPcode, [NumberOfUnits] = @NumberOfUnits, [PricePerUnit] = @PricePerUnit, [TotalAnnualFee] = @TotalAnnualFee, [Stationary] = @Stationary, [ContactPhoneW] = @ContactPhoneW, [ContactPhoneH] = @ContactPhoneH, [ContactPhoneM] = @ContactPhoneM, [Fax] = @Fax, [Email] = @Email, [WhyChooseUs] = @WhyChooseUs, [CurrentlyManagedBy] = @CurrentlyManagedBy, [DateSent] = @DateSent, [CallBackDate] = @CallBackDate, [StatusId] = @StatusId, [DocumentLink] = @DocumentLink, [EnteredBy] = @EnteredBy, [PictureLocation] = @PictureLocation WHERE (([QuoteId] = @Original_QuoteId) AND ((@IsNull_DateEntered = 1 AND [DateEntered] IS NULL) OR ([DateEntered] = @Original_DateEntered)) AND ((@IsNull_ContactName = 1 AND [ContactName] IS NULL) OR ([ContactName] = @Original_ContactName)) AND ((@IsNull_PreparedFor = 1 AND [PreparedFor] IS NULL) OR ([PreparedFor] = @Original_PreparedFor)) AND ((@IsNull_MailAddress1 = 1 AND [MailAddress1] IS NULL) OR ([MailAddress1] = @Original_MailAddress1)) AND ((@IsNull_MailAddress2 = 1 AND [MailAddress2] IS NULL) OR ([MailAddress2] = @Original_MailAddress2)) AND ((@IsNull_MASuburb = 1 AND [MASuburb] IS NULL) OR ([MASuburb] = @Original_MASuburb)) AND ((@IsNull_MAState = 1 AND [MAState] IS NULL) OR ([MAState] = @Original_MAState)) AND ((@IsNull_MAPcode = 1 AND [MAPcode] IS NULL) OR ([MAPcode] = @Original_MAPcode)) AND ((@IsNull_SPNumber = 1 AND [SPNumber] IS NULL) OR ([SPNumber] = @Original_SPNumber)) AND ((@IsNull_SPAddress1 = 1 AND [SPAddress1] IS NULL) OR ([SPAddress1] = @Original_SPAddress1)) AND ((@IsNull_SPAddress2 = 1 AND [SPAddress2] IS NULL) OR ([SPAddress2] = @Original_SPAddress2)) AND ((@IsNull_SPSuburb = 1 AND [SPSuburb] IS NULL) OR ([SPSuburb] = @Original_SPSuburb)) AND ((@IsNull_SPState = 1 AND [SPState] IS NULL) OR ([SPState] = @Original_SPState)) AND ((@IsNull_SPPcode = 1 AND [SPPcode] IS NULL) OR ([SPPcode] = @Original_SPPcode)) AND ((@IsNull_NumberOfUnits = 1 AND [NumberOfUnits] IS NULL) OR ([NumberOfUnits] = @Original_NumberOfUnits)) AND ((@IsNull_PricePerUnit = 1 AND [PricePerUnit] IS NULL) OR ([PricePerUnit] = @Original_PricePerUnit)) AND ((@IsNull_TotalAnnualFee = 1 AND [TotalAnnualFee] IS NULL) OR ([TotalAnnualFee] = @Original_TotalAnnualFee)) AND ((@IsNull_Stationary = 1 AND [Stationary] IS NULL) OR ([Stationary] = @Original_Stationary)) AND ((@IsNull_ContactPhoneW = 1 AND [ContactPhoneW] IS NULL) OR ([ContactPhoneW] = @Original_ContactPhoneW)) AND ((@IsNull_ContactPhoneH = 1 AND [ContactPhoneH] IS NULL) OR ([ContactPhoneH] = @Original_ContactPhoneH)) AND ((@IsNull_ContactPhoneM = 1 AND [ContactPhoneM] IS NULL) OR ([ContactPhoneM] = @Original_ContactPhoneM)) AND ((@IsNull_Fax = 1 AND [Fax] IS NULL) OR ([Fax] = @Original_Fax)) AND ((@IsNull_Email = 1 AND [Email] IS NULL) OR ([Email] = @Original_Email)) AND ((@IsNull_WhyChooseUs = 1 AND [WhyChooseUs] IS NULL) OR ([WhyChooseUs] = @Original_WhyChooseUs)) AND ((@IsNull_CurrentlyManagedBy = 1 AND [CurrentlyManagedBy] IS NULL) OR ([CurrentlyManagedBy] = @Original_CurrentlyManagedBy)) AND ((@IsNull_DateSent = 1 AND [DateSent] IS NULL) OR ([DateSent] = @Original_DateSent)) AND ((@IsNull_CallBackDate = 1 AND [CallBackDate] IS NULL) OR ([CallBackDate] = @Original_CallBackDate)) AND ((@IsNull_StatusId = 1 AND [StatusId] IS NULL) OR ([StatusId] = @Original_StatusId)) AND ((@IsNull_DocumentLink = 1 AND [DocumentLink] IS NULL) OR ([DocumentLink] = @Original_DocumentLink)) AND ((@IsNull_EnteredBy = 1 AND [EnteredBy] IS NULL) OR ([EnteredBy] = @Original_EnteredBy)) AND ((@IsNull_PictureLocation = 1 AND [PictureLocation] IS NULL) OR ([PictureLocation] = @Original_PictureLocation)));
SELECT QuoteId, DateEntered, ContactName, PreparedFor, MailAddress1, MailAddress2, MASuburb, MAState, MAPcode, SPNumber, SPAddress1, SPAddress2, SPSuburb, SPState, SPPcode, NumberOfUnits, PricePerUnit, TotalAnnualFee, Stationary, ContactPhoneW, ContactPhoneH, ContactPhoneM, Fax, Email, WhyChooseUs, CurrentlyManagedBy, DateSent, CallBackDate, StatusId, DocumentLink, EnteredBy, PictureLocation FROM Quote WHERE (QuoteId = @QuoteId)',N'@DateEntered datetime,@ContactName char(50),@PreparedFor char(50),@MailAddress1 char(50),@MailAddress2 char(8000),@MASuburb char(50),@MAState char(3),@MAPcode char(10),@SPNumber char(10),@SPAddress1 char(50),@SPAddress2 char(8000),@SPSuburb char(50),@SPState char(3),@SPPcode char(10),@NumberOfUnits int,@PricePerUnit money,@TotalAnnualFee money,@Stationary money,@ContactPhoneW char(8000),@ContactPhoneH char(8000),@ContactPhoneM char(8000),@Fax char(8000),@Email char(50),@WhyChooseUs char(50),@CurrentlyManagedBy char(50),@DateSent datetime,@CallBackDate datetime,@StatusId int,@DocumentLink char(8000),@EnteredBy char(15),@PictureLocation varchar(8000),@Original_QuoteId int,@IsNull_DateEntered int,@Original_DateEntered datetime,@IsNull_ContactName int,@Original_ContactName char(50),@IsNull_PreparedFor int,@Original_PreparedFor char(50),@IsNull_MailAddress1 int,@Original_MailAddress1 char(50),@IsNull_MailAddress2 int,@Original_MailAddress2 char(8000),@IsNull_MASuburb int,@Original_MASuburb char(50),@IsNull_MAState int,@Original_MAState char(3),@IsNull_MAPcode int,@Original_MAPcode char(10),@IsNull_SPNumber int,@Original_SPNumber char(10),@IsNull_SPAddress1 int,@Original_SPAddress1 char(50),@IsNull_SPAddress2 int,@Original_SPAddress2 char(8000),@IsNull_SPSuburb int,@Original_SPSuburb char(50),@IsNull_SPState int,@Original_SPState char(3),@IsNull_SPPcode int,@Original_SPPcode char(10),@IsNull_NumberOfUnits int,@Original_NumberOfUnits int,@IsNull_PricePerUnit int,@Original_PricePerUnit money,@IsNull_TotalAnnualFee int,@Original_TotalAnnualFee money,@IsNull_Stationary int,@Original_Stationary money,@IsNull_ContactPhoneW int,@Original_ContactPhoneW char(8000),@IsNull_ContactPhoneH int,@Original_ContactPhoneH char(8000),@IsNull_ContactPhoneM int,@Original_ContactPhoneM char(8000),@IsNull_Fax int,@Original_Fax char(8000),@IsNull_Email int,@Original_Email char(50),@IsNull_WhyChooseUs int,@Original_WhyChooseUs char(50),@IsNull_CurrentlyManagedBy int,@Original_CurrentlyManagedBy char(50),@IsNull_DateSent int,@Original_DateSent datetime,@IsNull_CallBackDate int,@Original_CallBackDate datetime,@IsNull_StatusId int,@Original_StatusId int,@IsNull_DocumentLink int,@Original_DocumentLink char(8000),@IsNull_EnteredBy int,@Original_EnteredBy char(15),@IsNull_PictureLocation int,@Original_PictureLocation varchar(8000),@QuoteId int',@DateEntered='2017-05-18 10:36:54.657',@ContactName='Herve Commiegnes ',@PreparedFor='Herve Commiegnes ',@MailAddress1='21 Westbrook Street ',@MailAddress2=NULL,@MASuburb='Beverly Hills ',@MAState='NSW',@MAPcode='2209 ',@SPNumber='54038 ',@SPAddress1='29 Riverside Cres ',@SPAddress2=NULL,@SPSuburb='Marrickville ',@SPState='NSW',@SPPcode='2204 ',@NumberOfUnits=4,@PricePerUnit=132.0000,@TotalAnnualFee=NULL,@Stationary=200.0000,@ContactPhoneW=NULL,@ContactPhoneH=NULL,@ContactPhoneM=NULL,@Fax=NULL,@Email='hervec@optushome.com.au ',@WhyChooseUs='Recommended ',@CurrentlyManagedBy='Fabos ',@DateSent='2005-12-28 00:00:00',@CallBackDate='2017-05-25 10:36:54.657',@StatusId=2,@DocumentLink=NULL,@EnteredBy='mpollard ',@PictureLocation=NULL,@Original_QuoteId=19,@IsNull_DateEntered=0,@Original_DateEntered='2017-05-17 09:33:37.480',@IsNull_ContactName=0,@Original_ContactName='Herve Commiegnes ',@IsNull_PreparedFor=0,@Original_PreparedFor='Herve Commiegnes ',@IsNull_MailAddress1=0,@Original_MailAddress1='21 Westbrook Street ',@IsNull_MailAddress2=1,@Original_MailAddress2=NULL,@IsNull_MASuburb=0,@Original_MASuburb='Beverly Hills ',@IsNull_MAState=0,@Original_MAState='NSW',@IsNull_MAPcode=0,@Original_MAPcode='2209 ',@IsNull_SPNumber=0,@Original_SPNumber='54038 ',@IsNull_SPAddress1=0,@Original_SPAddress1='29 Riverside Cres ',@IsNull_SPAddress2=1,@Original_SPAddress2=NULL,@IsNull_SPSuburb=0,@Original_SPSuburb='Marrickville ',@IsNull_SPState=0,@Original_SPState='NSW',@IsNull_SPPcode=0,@Original_SPPcode='2204 ',@IsNull_NumberOfUnits=0,@Original_NumberOfUnits=4,@IsNull_PricePerUnit=0,@Original_PricePerUnit=132.0000,@IsNull_TotalAnnualFee=1,@Original_TotalAnnualFee=NULL,@IsNull_Stationary=0,@Original_Stationary=200.0000,@IsNull_ContactPhoneW=1,@Original_ContactPhoneW=NULL,@IsNull_ContactPhoneH=1,@Original_ContactPhoneH=NULL,@IsNull_ContactPhoneM=1,@Original_ContactPhoneM=NULL,@IsNull_Fax=1,@Original_Fax=NULL,@IsNull_Email=0,@Original_Email='hervec@optushome.com.au ',@IsNull_WhyChooseUs=0,@Original_WhyChooseUs='Recommended ',@IsNull_CurrentlyManagedBy=0,@Original_CurrentlyManagedBy='Fabos ',@IsNull_DateSent=0,@Original_DateSent='2005-12-28 00:00:00',@IsNull_CallBackDate=0,@Original_CallBackDate='2017-05-24 09:33:37.480',@IsNull_StatusId=0,@Original_StatusId=2,@IsNull_DocumentLink=1,@Original_DocumentLink=NULL,@IsNull_EnteredBy=0,@Original_EnteredBy='mpollard ',@IsNull_PictureLocation=1,@Original_PictureLocation=NULL,@QuoteId=19
go
然后我再次做了相同的事情,但这次将日期设置在日期时间选择器中,而不是将它们保留在我的默认日期。 我明天(2017年5月19日)选择了截止日期和2017年5月26日的回拨日期。这次除了输入日期之外的所有字段都被插入到数据库中。
就是这么清楚。这次CallBackDate工作,Dated Entered没有。
生成相同的三个命令,重置,插入和更新
有人能发现这里发生了什么吗?
这是插入命令
exec sp_executesql N'INSERT INTO [Quote] ([DateEntered], [ContactName], [PreparedFor], [MailAddress1], [MailAddress2], [MASuburb], [MAState], [MAPcode], [SPNumber], [SPAddress1], [SPAddress2], [SPSuburb], [SPState], [SPPcode], [NumberOfUnits], [PricePerUnit], [TotalAnnualFee], [Stationary], [ContactPhoneW], [ContactPhoneH], [ContactPhoneM], [Fax], [Email], [WhyChooseUs], [CurrentlyManagedBy], [DateSent], [CallBackDate], [StatusId], [DocumentLink], [EnteredBy], [PictureLocation]) VALUES (@DateEntered, @ContactName, @PreparedFor, @MailAddress1, @MailAddress2, @MASuburb, @MAState, @MAPcode, @SPNumber, @SPAddress1, @SPAddress2, @SPSuburb, @SPState, @SPPcode, @NumberOfUnits, @PricePerUnit, @TotalAnnualFee, @Stationary, @ContactPhoneW, @ContactPhoneH, @ContactPhoneM, @Fax, @Email, @WhyChooseUs, @CurrentlyManagedBy, @DateSent, @CallBackDate, @StatusId, @DocumentLink, @EnteredBy, @PictureLocation);
SELECT QuoteId, DateEntered, ContactName, PreparedFor, MailAddress1, MailAddress2, MASuburb, MAState, MAPcode, SPNumber, SPAddress1, SPAddress2, SPSuburb, SPState, SPPcode, NumberOfUnits, PricePerUnit, TotalAnnualFee, Stationary, ContactPhoneW, ContactPhoneH, ContactPhoneM, Fax, Email, WhyChooseUs, CurrentlyManagedBy, DateSent, CallBackDate, StatusId, DocumentLink, EnteredBy, PictureLocation FROM Quote WHERE (QuoteId = SCOPE_IDENTITY())',N'@DateEntered datetime,@ContactName char(12),@PreparedFor char(12),@MailAddress1 char(16),@MailAddress2 char(16),@MASuburb char(11),@MAState char(3),@MAPcode char(4),@SPNumber char(8),@SPAddress1 char(18),@SPAddress2 char(18),@SPSuburb char(6),@SPState char(2),@SPPcode char(4),@NumberOfUnits int,@PricePerUnit money,@TotalAnnualFee money,@Stationary money,@ContactPhoneW char(11),@ContactPhoneH char(11),@ContactPhoneM char(11),@Fax char(11),@Email char(12),@WhyChooseUs char(13),@CurrentlyManagedBy char(20),@DateSent datetime,@CallBackDate datetime,@StatusId int,@DocumentLink char(8000),@EnteredBy char(8000),@PictureLocation varchar(57)',@DateEntered='2017-05-19 11:38:53',@ContactName='CONTACT NAME',@PreparedFor='PREPARED FOR',@MailAddress1='MAIL ADDRESS ONE',@MailAddress2='MAIL ADDRESS TWO',@MASuburb='MAIL SUBURB',@MAState='NSW',@MAPcode='2000',@SPNumber='12345678',@SPAddress1='STRATA ADDRESS ONE',@SPAddress2='STRATA ADDRESS TWO',@SPSuburb='SUBURB',@SPState='SA',@SPPcode='2001',@NumberOfUnits=100,@PricePerUnit=200.0000,@TotalAnnualFee=20000.0000,@Stationary=100.0000,@ContactPhoneW='01 12345678',@ContactPhoneH='02 12345678',@ContactPhoneM='03 12345678',@Fax='03 12345678',@Email='my@email.com',@WhyChooseUs='WHY CHOOSE US',@CurrentlyManagedBy='CURRENTLY MANAGED BY',@DateSent=NULL,@CallBackDate='2017-05-26 11:38:53',@StatusId=NULL,@DocumentLink=NULL,@EnteredBy=NULL,@PictureLocation='C:\Temp\QuoteMasterPlus\Photos\STRATAADDRESSONESUBURB.jpg'
go
这是更新命令
exec sp_executesql N'UPDATE [Quote] SET [DateEntered] = @DateEntered, [ContactName] = @ContactName, [PreparedFor] = @PreparedFor, [MailAddress1] = @MailAddress1, [MailAddress2] = @MailAddress2, [MASuburb] = @MASuburb, [MAState] = @MAState, [MAPcode] = @MAPcode, [SPNumber] = @SPNumber, [SPAddress1] = @SPAddress1, [SPAddress2] = @SPAddress2, [SPSuburb] = @SPSuburb, [SPState] = @SPState, [SPPcode] = @SPPcode, [NumberOfUnits] = @NumberOfUnits, [PricePerUnit] = @PricePerUnit, [TotalAnnualFee] = @TotalAnnualFee, [Stationary] = @Stationary, [ContactPhoneW] = @ContactPhoneW, [ContactPhoneH] = @ContactPhoneH, [ContactPhoneM] = @ContactPhoneM, [Fax] = @Fax, [Email] = @Email, [WhyChooseUs] = @WhyChooseUs, [CurrentlyManagedBy] = @CurrentlyManagedBy, [DateSent] = @DateSent, [CallBackDate] = @CallBackDate, [StatusId] = @StatusId, [DocumentLink] = @DocumentLink, [EnteredBy] = @EnteredBy, [PictureLocation] = @PictureLocation WHERE (([QuoteId] = @Original_QuoteId) AND ((@IsNull_DateEntered = 1 AND [DateEntered] IS NULL) OR ([DateEntered] = @Original_DateEntered)) AND ((@IsNull_ContactName = 1 AND [ContactName] IS NULL) OR ([ContactName] = @Original_ContactName)) AND ((@IsNull_PreparedFor = 1 AND [PreparedFor] IS NULL) OR ([PreparedFor] = @Original_PreparedFor)) AND ((@IsNull_MailAddress1 = 1 AND [MailAddress1] IS NULL) OR ([MailAddress1] = @Original_MailAddress1)) AND ((@IsNull_MailAddress2 = 1 AND [MailAddress2] IS NULL) OR ([MailAddress2] = @Original_MailAddress2)) AND ((@IsNull_MASuburb = 1 AND [MASuburb] IS NULL) OR ([MASuburb] = @Original_MASuburb)) AND ((@IsNull_MAState = 1 AND [MAState] IS NULL) OR ([MAState] = @Original_MAState)) AND ((@IsNull_MAPcode = 1 AND [MAPcode] IS NULL) OR ([MAPcode] = @Original_MAPcode)) AND ((@IsNull_SPNumber = 1 AND [SPNumber] IS NULL) OR ([SPNumber] = @Original_SPNumber)) AND ((@IsNull_SPAddress1 = 1 AND [SPAddress1] IS NULL) OR ([SPAddress1] = @Original_SPAddress1)) AND ((@IsNull_SPAddress2 = 1 AND [SPAddress2] IS NULL) OR ([SPAddress2] = @Original_SPAddress2)) AND ((@IsNull_SPSuburb = 1 AND [SPSuburb] IS NULL) OR ([SPSuburb] = @Original_SPSuburb)) AND ((@IsNull_SPState = 1 AND [SPState] IS NULL) OR ([SPState] = @Original_SPState)) AND ((@IsNull_SPPcode = 1 AND [SPPcode] IS NULL) OR ([SPPcode] = @Original_SPPcode)) AND ((@IsNull_NumberOfUnits = 1 AND [NumberOfUnits] IS NULL) OR ([NumberOfUnits] = @Original_NumberOfUnits)) AND ((@IsNull_PricePerUnit = 1 AND [PricePerUnit] IS NULL) OR ([PricePerUnit] = @Original_PricePerUnit)) AND ((@IsNull_TotalAnnualFee = 1 AND [TotalAnnualFee] IS NULL) OR ([TotalAnnualFee] = @Original_TotalAnnualFee)) AND ((@IsNull_Stationary = 1 AND [Stationary] IS NULL) OR ([Stationary] = @Original_Stationary)) AND ((@IsNull_ContactPhoneW = 1 AND [ContactPhoneW] IS NULL) OR ([ContactPhoneW] = @Original_ContactPhoneW)) AND ((@IsNull_ContactPhoneH = 1 AND [ContactPhoneH] IS NULL) OR ([ContactPhoneH] = @Original_ContactPhoneH)) AND ((@IsNull_ContactPhoneM = 1 AND [ContactPhoneM] IS NULL) OR ([ContactPhoneM] = @Original_ContactPhoneM)) AND ((@IsNull_Fax = 1 AND [Fax] IS NULL) OR ([Fax] = @Original_Fax)) AND ((@IsNull_Email = 1 AND [Email] IS NULL) OR ([Email] = @Original_Email)) AND ((@IsNull_WhyChooseUs = 1 AND [WhyChooseUs] IS NULL) OR ([WhyChooseUs] = @Original_WhyChooseUs)) AND ((@IsNull_CurrentlyManagedBy = 1 AND [CurrentlyManagedBy] IS NULL) OR ([CurrentlyManagedBy] = @Original_CurrentlyManagedBy)) AND ((@IsNull_DateSent = 1 AND [DateSent] IS NULL) OR ([DateSent] = @Original_DateSent)) AND ((@IsNull_CallBackDate = 1 AND [CallBackDate] IS NULL) OR ([CallBackDate] = @Original_CallBackDate)) AND ((@IsNull_StatusId = 1 AND [StatusId] IS NULL) OR ([StatusId] = @Original_StatusId)) AND ((@IsNull_DocumentLink = 1 AND [DocumentLink] IS NULL) OR ([DocumentLink] = @Original_DocumentLink)) AND ((@IsNull_EnteredBy = 1 AND [EnteredBy] IS NULL) OR ([EnteredBy] = @Original_EnteredBy)) AND ((@IsNull_PictureLocation = 1 AND [PictureLocation] IS NULL) OR ([PictureLocation] = @Original_PictureLocation)));
SELECT QuoteId, DateEntered, ContactName, PreparedFor, MailAddress1, MailAddress2, MASuburb, MAState, MAPcode, SPNumber, SPAddress1, SPAddress2, SPSuburb, SPState, SPPcode, NumberOfUnits, PricePerUnit, TotalAnnualFee, Stationary, ContactPhoneW, ContactPhoneH, ContactPhoneM, Fax, Email, WhyChooseUs, CurrentlyManagedBy, DateSent, CallBackDate, StatusId, DocumentLink, EnteredBy, PictureLocation FROM Quote WHERE (QuoteId = @QuoteId)',N'@DateEntered datetime,@ContactName char(50),@PreparedFor char(50),@MailAddress1 char(50),@MailAddress2 char(8000),@MASuburb char(50),@MAState char(3),@MAPcode char(10),@SPNumber char(10),@SPAddress1 char(50),@SPAddress2 char(8000),@SPSuburb char(50),@SPState char(3),@SPPcode char(10),@NumberOfUnits int,@PricePerUnit money,@TotalAnnualFee money,@Stationary money,@ContactPhoneW char(8000),@ContactPhoneH char(8000),@ContactPhoneM char(8000),@Fax char(8000),@Email char(50),@WhyChooseUs char(50),@CurrentlyManagedBy char(50),@DateSent datetime,@CallBackDate datetime,@StatusId int,@DocumentLink char(8000),@EnteredBy char(15),@PictureLocation varchar(8000),@Original_QuoteId int,@IsNull_DateEntered int,@Original_DateEntered datetime,@IsNull_ContactName int,@Original_ContactName char(50),@IsNull_PreparedFor int,@Original_PreparedFor char(50),@IsNull_MailAddress1 int,@Original_MailAddress1 char(50),@IsNull_MailAddress2 int,@Original_MailAddress2 char(8000),@IsNull_MASuburb int,@Original_MASuburb char(50),@IsNull_MAState int,@Original_MAState char(3),@IsNull_MAPcode int,@Original_MAPcode char(10),@IsNull_SPNumber int,@Original_SPNumber char(10),@IsNull_SPAddress1 int,@Original_SPAddress1 char(50),@IsNull_SPAddress2 int,@Original_SPAddress2 char(8000),@IsNull_SPSuburb int,@Original_SPSuburb char(50),@IsNull_SPState int,@Original_SPState char(3),@IsNull_SPPcode int,@Original_SPPcode char(10),@IsNull_NumberOfUnits int,@Original_NumberOfUnits int,@IsNull_PricePerUnit int,@Original_PricePerUnit money,@IsNull_TotalAnnualFee int,@Original_TotalAnnualFee money,@IsNull_Stationary int,@Original_Stationary money,@IsNull_ContactPhoneW int,@Original_ContactPhoneW char(8000),@IsNull_ContactPhoneH int,@Original_ContactPhoneH char(8000),@IsNull_ContactPhoneM int,@Original_ContactPhoneM char(8000),@IsNull_Fax int,@Original_Fax char(8000),@IsNull_Email int,@Original_Email char(50),@IsNull_WhyChooseUs int,@Original_WhyChooseUs char(50),@IsNull_CurrentlyManagedBy int,@Original_CurrentlyManagedBy char(50),@IsNull_DateSent int,@Original_DateSent datetime,@IsNull_CallBackDate int,@Original_CallBackDate datetime,@IsNull_StatusId int,@Original_StatusId int,@IsNull_DocumentLink int,@Original_DocumentLink char(8000),@IsNull_EnteredBy int,@Original_EnteredBy char(15),@IsNull_PictureLocation int,@Original_PictureLocation varchar(8000),@QuoteId int',@DateEntered='2017-05-18 11:38:53.353',@ContactName='Herve Commiegnes ',@PreparedFor='Herve Commiegnes ',@MailAddress1='21 Westbrook Street ',@MailAddress2=NULL,@MASuburb='Beverly Hills ',@MAState='NSW',@MAPcode='2209 ',@SPNumber='54038 ',@SPAddress1='29 Riverside Cres ',@SPAddress2=NULL,@SPSuburb='Marrickville ',@SPState='NSW',@SPPcode='2204 ',@NumberOfUnits=4,@PricePerUnit=132.0000,@TotalAnnualFee=NULL,@Stationary=200.0000,@ContactPhoneW=NULL,@ContactPhoneH=NULL,@ContactPhoneM=NULL,@Fax=NULL,@Email='hervec@optushome.com.au ',@WhyChooseUs='Recommended ',@CurrentlyManagedBy='Fabos ',@DateSent='2005-12-28 00:00:00',@CallBackDate='2017-05-25 11:38:53.353',@StatusId=2,@DocumentLink=NULL,@EnteredBy='mpollard ',@PictureLocation=NULL,@Original_QuoteId=19,@IsNull_DateEntered=0,@Original_DateEntered='2017-05-18 10:36:54.657',@IsNull_ContactName=0,@Original_ContactName='Herve Commiegnes ',@IsNull_PreparedFor=0,@Original_PreparedFor='Herve Commiegnes ',@IsNull_MailAddress1=0,@Original_MailAddress1='21 Westbrook Street ',@IsNull_MailAddress2=1,@Original_MailAddress2=NULL,@IsNull_MASuburb=0,@Original_MASuburb='Beverly Hills ',@IsNull_MAState=0,@Original_MAState='NSW',@IsNull_MAPcode=0,@Original_MAPcode='2209 ',@IsNull_SPNumber=0,@Original_SPNumber='54038 ',@IsNull_SPAddress1=0,@Original_SPAddress1='29 Riverside Cres ',@IsNull_SPAddress2=1,@Original_SPAddress2=NULL,@IsNull_SPSuburb=0,@Original_SPSuburb='Marrickville ',@IsNull_SPState=0,@Original_SPState='NSW',@IsNull_SPPcode=0,@Original_SPPcode='2204 ',@IsNull_NumberOfUnits=0,@Original_NumberOfUnits=4,@IsNull_PricePerUnit=0,@Original_PricePerUnit=132.0000,@IsNull_TotalAnnualFee=1,@Original_TotalAnnualFee=NULL,@IsNull_Stationary=0,@Original_Stationary=200.0000,@IsNull_ContactPhoneW=1,@Original_ContactPhoneW=NULL,@IsNull_ContactPhoneH=1,@Original_ContactPhoneH=NULL,@IsNull_ContactPhoneM=1,@Original_ContactPhoneM=NULL,@IsNull_Fax=1,@Original_Fax=NULL,@IsNull_Email=0,@Original_Email='hervec@optushome.com.au ',@IsNull_WhyChooseUs=0,@Original_WhyChooseUs='Recommended ',@IsNull_CurrentlyManagedBy=0,@Original_CurrentlyManagedBy='Fabos ',@IsNull_DateSent=0,@Original_DateSent='2005-12-28 00:00:00',@IsNull_CallBackDate=0,@Original_CallBackDate='2017-05-25 10:36:54.657',@IsNull_StatusId=0,@Original_StatusId=2,@IsNull_DocumentLink=1,@Original_DocumentLink=NULL,@IsNull_EnteredBy=0,@Original_EnteredBy='mpollard ',@IsNull_PictureLocation=1,@Original_PictureLocation=NULL,@QuoteId=19
go
查看捕获的SQL的更新部分对我来说完全没有意义。参数中的详细信息用于完全不同的记录。我正在创建一个ID为2122或者其中的新记录,并且更新的记录是ID 19.果然,如果我查看ID为19的记录,我看到真正的旧数据〜2006年已经更新了2017年日期。 视觉工作室究竟如何提出这个SQL?
更奇怪的是,它总是更新记录ID 19,这是表中的第一条记录。
答案 0 :(得分:0)
从我所看到的:
在没有看到代码的情况下我无法确定,但我假设您在为@DateEntered设置参数的位置不正确。
答案 1 :(得分:0)
我无法相信这是多么简单。
我的FormMainLoad看起来像这样。
1)填写我的数据集(第一条记录作为当前记录加载)
2)设置我的默认日期(猜猜它改变了第一条记录)
3)将对话框设置为开始新记录。
Bingo:他们的顺序错误
当我去保存时,它会对第一条记录进行更新,并在新记录上进行插入。
private void FormMain_Load(object sender, EventArgs e)
{
// This line of code loads data into the 'quoteDataSet.Quote' table. You can move, or remove it, as needed.
this.quoteTableAdapter.Fill(this.quoteDataSet.Quote);
// Set the Date entered to Today
dateTimePickerDateEntered.Value = DateTime.Now;
// Set the call back date to Today + 7 days
dateTimePickerCallBackDate.Value = DateTime.Now.AddDays(7);
//Start the dialog in Add New Record Mode
this.quoteBindingNavigator.Items["bindingNavigatorAddNewItem"].PerformClick();
}
所以我将命令的顺序改为
1)加载数据集
2)设置对话框以开始新记录
3)设置默认日期
它有效。有趣的是我假设问题是日期时间选择器让我开始疯狂追逐。再加上我最初没有注意到第一条记录正在更新。
private void FormMain_Load(object sender, EventArgs e)
{
// This line of code loads data into the 'quoteDataSet.Quote' table. You can move, or remove it, as needed.
this.quoteTableAdapter.Fill(this.quoteDataSet.Quote);
//Start the dialog in Add New Record Mode
this.quoteBindingNavigator.Items["bindingNavigatorAddNewItem"].PerformClick();
// Set the Date entered to Today
dateTimePickerDateEntered.Value = DateTime.Now;
// Set the call back date to Today + 7 days
dateTimePickerCallBackDate.Value = DateTime.Now.AddDays(7);
}
感谢所有评论的人。 回答你的问题迫使我更加努力地看待我的代码并逐步加深它,直到答案击中我的脸。