Microsoft 开发人员网络 > 论坛主页 > 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日 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.

答案

  • 2009年7月2日 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.

全部回复

  • 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日 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.