Omit database-calculated field from ADO.Net validation

0

Full disclaimer: I'm a total C# <-> DB noob. I'm not bad at C#, and I'm not bad at Access, but integrating the two is new to me.

In my project, I'm using OleDB / ADO.Net (I guess -- honestly, I'm just taking the internet's word for it) and Visual Studio's built-in DataSource wizard to deal with an Access database.

Everything seems to [finally] be working okay, until I get to validation. On validation, I believe the program tries to validate the DataSet against the DB, and that's where my error occurs -- I have a calculated field that doesn't seem to want to validate.

I would love to be able to exclude just that field from the pushed updates.

So my save code is this:

    private void saveDatabase()
    {
        this.Validate();
        this.standardizedPatientsBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.hSS_SPsDataSet);  
    }

When I validate, it throws this error:

    System.Data.OleDb.OleDbException (0x80040E21): Cannot update 'FullName'; field not updateable.
    [... a list of all the methods where it breaks, many of which are called behind the scenes...]

I know WHY it's not updateable -- it's a calculated field -- but what I can't figure out is how to ignore that field.

c#
visual-studio
ms-access
ado.net
asked on Stack Overflow Feb 19, 2014 by Dave Matney

1 Answer

1

You will most likely have to manually edit the UpdateCommand (and also the InsertCommand) associated with the TableAdapter for said DataTable in your DataSet.

You can use the graphical query builder to remove the FullName field from the update and insert queries.

I'm not aware that this can be done automatically for Access calculated fields. I could be wrong though.

Cheers

answered on Stack Overflow Feb 19, 2014 by Luc Morin

User contributions licensed under CC BY-SA 3.0