How to auto calculate two rows into third one in datagridview table who uses access database

DRGAGI 146 Reputation points
2020-12-02T17:51:10.327+00:00

I insert Access database into Visual Studio Basic. I have put datagridview on the form who uses same database. What i am ask is: How to auto calculate one of the row cell as product of another two, within same datagridview, same database. When you enter value in the rows to auto calculate value without using another button or extra code?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,670 questions
{count} votes

Accepted answer
  1. Karen Payne MVP 35,386 Reputation points
    2020-12-03T18:42:11.487+00:00

    Hello @DRGAGI

    In the .xsd file, select the table, add a new column

    44951-000.png

    Now setup the Expression for the column just added. In the following UnitPrice column exist in the database table as a decimal, the new column has been setup as a decimal and an Expression as shown. This works when saving as the column is ignored by the database classes.

    Does this make sense?

    44961-1111.png

    1 person found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Xingyu Zhao-MSFT 5,361 Reputation points
    2020-12-03T02:23:35.667+00:00

    Hi @DRGAGI ,
    As LesHay suggested, you need to add following code in your 'Form.Load' event.

    yourDataSet.Tables("yourTable").Columns("TotalColumnName").Expression = "yourColumnName1 * yourColumnName2"  
    

    Result of my test.
    44621-gif.gif

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Anonymous
    2020-12-02T18:37:35.097+00:00

    Hi
    You could use Expressions to do this. See HERE for details.

    0 comments No comments

  3. DRGAGI 146 Reputation points
    2020-12-03T16:54:21.267+00:00

    Thank you for your support guys. Code works fine, but when i want to save database i get this error44778-snap2.jpg


  4. DRGAGI 146 Reputation points
    2020-12-03T20:32:15.063+00:00
    Public Class Form1
        Private Sub Table1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Table1BindingNavigatorSaveItem.Click
            Me.Validate()
            Me.Table1BindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.DatabaseTestDataSet)
    
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'DatabaseTestDataSet.Table1' table. You can move, or remove it, as needed.
            Me.Table1TableAdapter.Fill(Me.DatabaseTestDataSet.Table1)
    
            DatabaseTestDataSet.Tables("Table1").Columns("sum").Expression = "a1 * a2"
    
    
        End Sub
    End Class
    
    0 comments No comments