Microsoft Developer Network > 포럼 홈 > Visual Studio Debugger > Cannot insert row into SQL 2005 express edition database using Linq
질문하기질문하기
 

답변됨Cannot insert row into SQL 2005 express edition database using Linq

  • 2009년 6월 26일 금요일 오후 7:30wolferene 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    I am getting the error "Can't perform Create, Update or Delete operations on 'Table(Flight)' because it has no primary key."

    When the user clicks in the button on my form I want to insert a new row into my database. The database is called reservations.
    I am using the code from MSDN on how to insert a column using LINQ. This is my code:

       Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim database As New Airline.ReservationsDataClassesDataContext
    
            Dim fl As New Airline.Flight
            fl.ID = GetSelectedId2()
            fl.Date = DateTextBox.Text
            fl.ItemName = ItemNameTextBox.Text
            fl.Price = PriceTextBox.Text
    
            database.Flights.InsertOnSubmit(fl)
    
            database.SubmitChanges()
        End Sub
    
    I am at a dead end. Please let me know if you have any suggestions or need additional information. I do have the primary key of this table's identity property set to "yes" and I have it set to auto increment.

    Thanks.

답변

  • 2009년 7월 2일 목요일 오후 10:46wolferene 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    THANKS! I checked my dtml file and sure enough it was using the wrong table... not even sure where it was pulling it from :( oh well, I got it straightend out. Thanks for pointing me in the right direction.

모든 응답

  • 2009년 6월 30일 화요일 오전 5:54Roahn LuoMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Hello,

    I'm a little confused with the data table you use, is it named Flight or Flights? The error message indicates that we are operating the Talbe Flight, while in the code, we actually access the Flights table which may map to the Flight table in the database, you may find the definition of those two objects in the .dbml file and to see if they are matched. If we re-add the Flight/Flights table, how about the issue?

    Also, I recommend you post thread in our Linq to SQL forum for more help.

    Best regards,

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
  • 2009년 7월 2일 목요일 오후 10:46wolferene 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    THANKS! I checked my dtml file and sure enough it was using the wrong table... not even sure where it was pulling it from :( oh well, I got it straightend out. Thanks for pointing me in the right direction.