2016-08-22 96 views
-1

我使用表適配器將數據插入到我的數據庫:插入數據,更新如果「ID」的存在已經

JUTDMSTableAdapters.textBooksTableAdapter bookTableAdapter; 
bookTableAdapter = new JUTDMSTableAdapters.textBooksTableAdapter(); 
JUTDMSTableAdapters.CourseTableAdapter courseTableAdapter; 
courseTableAdapter = new JUTDMSTableAdapters.CourseTableAdapter(); 
courseTableAdapter.Insert(CourseID: txtCourseID.Text, CourseTitle: txtCourseTitle.Text); 
bookTableAdapter.Insert(thirteenISBN: txt13ISBN.Text, CourseID: txtCourseID.Text, BookTitle: txtBookTitle.Text, Ancillary: txtAncillary.Text, 
BookActive: txtBookActive.Text, ActiveDate: txtActiveDate.Text, InactiveDate: txtInactiveDate.Text, Author: txtAuthor.Text, 
      Imprint: txtImprint.Text, Publisher: txtPublisher.Text, EditionAndDate: txtEditionDate.Text, 
VendorISBN: vendISBN, tenISBN: txt10ISBN.Text, ebookAvailable: txtEBookAvailable.Text, eISBN: txtEISBN.Text, Notes: txtNotes.Text); 

當我插入一個新的課本我在「CourseID」輸入,並將其添加記錄到父表「課程」我的問題是,每次我添加一個新的課本時,如果courseID已經存在,它仍然會向父級「課程」表中添加一條新記錄。如果CourseID存在,我需要更新當前數據庫,如果沒有,則需要添加,但是我沒有看到有關表格適配器的任何內容。

+0

你需要顯示你的SQL關於'If Exist'也爲什麼不添加Sql到存儲過程vs依賴於附加到TableAdapter的SQL。你需要顯示所有相關的代碼.. – MethodMan

+0

我想知道的是,如果有一種方法可以將此插入語句放入if語句並檢查courseID。我沒有線索。以前從未使用過c#,這是我的第一次應用 – Norque

+0

你有沒有購買過新車或二手車?如是 ;那麼你是否必須學習如何「再學習如何駕駛......?」 – MethodMan

回答

0

檢查課程是否已通過分開的查詢存在,然後插入或更新課程。

相關問題