MSDN > Home page del forum > Visual Studio Debugger > Cannot insert row into SQL 2005 express edition database using Linq
Formula una domandaFormula una domanda
 

Con rispostaCannot insert row into SQL 2005 express edition database using Linq

  • venerdì 26 giugno 2009 19.30wolferene Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Contiene codice
    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.

Risposte

  • giovedì 2 luglio 2009 22.46wolferene Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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.

Tutte le risposte

  • martedì 30 giugno 2009 5.54Roahn LuoMSFT, ModeratoreMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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!
  • giovedì 2 luglio 2009 22.46wolferene Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con risposta
    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.