MSDN > 論壇首頁 > 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

  • Friday, 26 June, 2009 19: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.

解答

  • Thursday, 2 July, 2009 22: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.

所有回覆

  • Tuesday, 30 June, 2009 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!
  • Thursday, 2 July, 2009 22: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.