2017-05-17 18 views
0

データベースに多くの値が書き込まれたWindowsフォームアプリケーションがあります。それはDataSetと、通常の自動生成されたテーブルアダプタなどを使用しています。私はこれを手にしませんでした。私は単にデータソースタブからフィールドをドラッグしてフォームにドロップしました。自動生成されたSQLは正常に見えます。SQL ServerデータベースにDateTimePicker値が保存されていません

私は2つのコントロールデータを同じ方法でバインドしていますが、デフォルト値を使用するとどちらもデータベースに書き込まれません。 SQL Serverのデータ形式はdatetimeです。

フォームのLoadメソッドから、このような初期日付の値を設定しています。

// 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コントロールを使用して手動で日付を変更すると、正常にデータベースに保存されます。私はこの問題をGoogleにして、私がすでにやっていることを示唆する解決策を見つけました。

実際に今日選択すると、デフォルト値が画面上に表示され、変更されていないように見えます。

私は別のことをすべきですか?

おかげ デビッド

UPDATE

は、私は、デフォルトの日付を保存し、実行し、SQLプロファイルエクスプレスと呼ばれるツールを使用してサーバから生成されたSQLを捕獲しました。

実行された3つのコマンドがありました。

幹部sp_resetConnection

幹部sp_executesqlを私はなぜそれが更新をやっているかわからない

のexec sp_executesqlを更新

を挿入します。それは、既存の無関係のレコードを更新しようとしているようで、私は新しいレコードを挿入しています。 主キーのQuoteIDフィールドはIDフィールドです。

はここでここで挿入

`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='[email protected]',@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='[email protected]       ',@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='[email protected]       ',@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が働いて日付が記入されました。生成された

同じ3つのコマンド、リセット、挿入および

を更新誰もがここで何が起こっているか見つけることができますか?ここで

は、それが私には全く意味がありません撮影しSQLの更新部分を見てみると、更新コマンド

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='[email protected]       ',@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='[email protected]       ',@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 

UPDATE 2

挿入コマンドここで

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='[email protected]',@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 

されています。パラメータの詳細は完全に異なるレコード用です。私は新しいレコードを作成しています。IDは2122かそこらで更新され、ID 19のレコードが更新されています。ID 19のレコードを見ると、本当に古いデータ〜2006が2017日付で更新されています。 ビジュアルスタジオはどのようにこのSQLを考案しましたか?

見知らぬ人でも、テーブルの最初のレコードであるレコードID 19が常に更新されるようです。私が見ることができるものから、

+0

datatimepickerの値がsqlparametersにマップされるコードを追加できますか? 今日選択すると日付が挿入されますか? – Scrobi

+0

Sql Server Profilerを使用する –

+0

@Scrobi日付時刻選択コントロールを使用して日付を変更すると、データベースに正常に保存されることに言及しました。 –

答えて

0

これがどれほど簡単かは分かりません。

My FormMainLoadはこのように見えます。

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

     // 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(); 
    } 

だから私は

2のデータセットをロードします)この

1にコマンドの順序を変更)、新しいレコード

3を開始するためのダイアログを設定)デフォルトの日付を設定します。

これは機能します。面白い私は問題を仮定してdatetime pickerと私は野生のガチョウの追跡に私を始めた。初めのレコードが更新されたことに最初は気付かなかった私と一緒になった。

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

コメントありがとうございました。 あなたの質問に答えると、私のコードをより見やすく見せてくれました。答えが私の顔を叩くまでは、そのコードをもっとゆっくりと深く進んで行きました。

0

  1. 挿入1 @DateEntered = NULL
  2. アップデート1 @DateEntered = 2017年5月18日10:36:54.657
  3. 挿入2 @DateEntered = 2017- 05-19 11:38:53
  4. 更新2 @DateEntered = 2017-05-18 11:38:53.353。

コードを見ることなく、私は確信することはできませんが、@ DateEnteredのパラメータを設定する場所が間違っていると推測しています。

+0

新しいレコードを作成しているときには、そのレコードを挿入して更新するのではなく、更新する必要があると仮定して修正します。これはすべて自動的に生成されたコードなので、プロジェクトのバックアップを作成し、すべてのデータ接続を削除してから再開することがあります。私のデータセットは1つのテーブルしか持っていないので、これがどのようにレールから外れたのか分かりません。これを見ていただきありがとうございます。私は現時点ではコードを進んでいるが、遠くには進まない。 –

+0

あなたは通常これを推測しますが、それはSQLコードを自動的に生成するために使用しているものによって異なる場合があります。 'SqlParameter param = new SqlParameter(" @ DateEntered "、SqlDbType.DateTime)のようなコードはありませんparam.value = << comboboxvalue >> – Scrobi

関連する問題