Search code examples
c#ms-access-2003

How to implement calculation in access 2003


I have an access database that am trying to add some calculation and use my c# application to pull data using a dataGridView,

I have about 14 fields in this particular table, I was wondering if there is way

I could perform a calculation from field 1 based on field 11 and 12? both field 11 and 12 are accepts numbers and so too field 1 I want field one to have data that is as field1==>{field11-field12) How can I accomplish this in access 2003.


Solution

  • Create a query in Access, then you can enter the calculation as a new field in that query. When you create the query, Access will give you a series of checkboxes where you can select which fields you want in the result.

    It is easiest to add the calculation if you go to SQL view in the query editor. Then you will see something like

    select field2, field3, field4 from SomeTable
    

    and you want to add your calculation as a new column

    select field2, field3, field4, (field11 - field12) as fieldDifference from SomeTable
    

    Then save your query.

    In your C# code, instead of having the data source refer to the table name (SomeTable in this example) use the name that you saved the query as.