none
Errors with inserting and updating database table with linq RRS feed

  • Question

  • First it is a Microsoft Access database.

    The definition of the database table:

    [Person]

    ID: auto number

    Name: text(20)

    Address: text(50)

     

    In c#, I mapped this table to

    [Table]

    class Person

    {

    [Column(IsPrimaryKey=true, isDbGenerated=true)]

    public int ID {get; set;}

    [Column]

    public string Name{get; set;}

    [Column]

    public string Address{get; set;}

    }

     

    Opend the database and get the table:

    string connectionString = "Provider=.....";

    OleDbConnection con = new OleDbConnection(connectionString);

    DataContext ctx = new DataContext(con);

    Table persons = ctx.GetTable<Person>;

     

    Now, I can search and delete any data in the table without error or exception, but If I insert a new row:

    Person p = new Person();

    p.Name="Tom";

    p.Address="Beijing";

    persons.InsertOnSubmit(p);

    ctx.SubmitChanges();

    Then I got an exception said that an semicolon ";" lost at the last of the sql string. Why?

    And also exception got while updating, said something like that the sql string is not valid. Why?

    Wednesday, February 27, 2008 4:55 AM

Answers

  • What provider are you using? Presumaby "LINQ to SQL"?

     

    This only supports SQL Server variants. One option would be to switch to SQL Server Express Edition (free), which is much more powerful than Jet (aka Access db) in many, many ways...

     

    Alternatively you'll have to find a LINQ to Jet provider, perhaps as a 3rd-party plugin to ADO.NET Entity Framework [beta].

     

    Personally, I'd switch to SQL Express without hesitation (if possible in your environment).

     

    Marc

     

    Wednesday, February 27, 2008 8:03 AM