Hi ,

I am new to VB.NET.I am creating an database windows application in VS2010 and SQL server 2008 express.In one of my form i have a datagrid.

My requirement is that i want to display the sum of an column of a DB table and other related data from other tables in the datagrid which is having 4 fields :
1. MatNo , 2.Quantity ,3. Opening Stock , 4. Closing Stock

Db table1 hav following fields : MatNo , Qty1

Qty1 is the field for which i hav to find the sum against MatNo entered by user.

In Db table2 hav again following fields : MatNo , Qty2

Mapping of data to datagrid :
1. MatNo : will contain the Matno entered by user.User can also enter a range of material like from 1000 to 2000.

2. Quantity : For each of the material entered calculate sum of QTY1 from Db table1.

3. Opening Stock : value in Quantity field of datagrid - value of QTY2 from Db table2 based on some select query ).

4. Closing Stock : value in opening stock of datagrid - value of QTY2 from Db table2 based on some select query )

what could be the best way to do it.I am using VB.net windows form with SQL

I think all the above requirement can be done by SQL and the output needs to be populated in the grid.

Hi ,

I am new to VB.NET.I am creating an database windows application in VS2010 and SQL server 2008 express.In one of my form i have a datagrid.

My requirement is that i want to display the sum of an column of a DB table and other related data from other tables in the datagrid which is having 4 fields :
1. MatNo , 2.Quantity ,3. Opening Stock , 4. Closing Stock

Db table1 hav following fields : MatNo , Qty1

Qty1 is the field for which i hav to find the sum against MatNo entered by user.

In Db table2 hav again following fields : MatNo , Qty2

Mapping of data to datagrid :
1. MatNo : will contain the Matno entered by user.User can also enter a range of material like from 1000 to 2000.

2. Quantity : For each of the material entered calculate sum of QTY1 from Db table1.

3. Opening Stock : value in Quantity field of datagrid - value of QTY2 from Db table2 based on some select query ).

4. Closing Stock : value in opening stock of datagrid - value of QTY2 from Db table2 based on some select query )

what could be the best way to do it.I am using VB.net windows form with SQL

try this code first get all the data from ur database column once the datagrid is filled then try to sum what ever columns u want to hope this will work for u.

Public Function GetTotalSum(ByVal DgvBill As DataGridView) As Integer
        Dim sum As Double = 0
        Try
            For i = 0 To DgvBill.RowCount - 2
                sum += DgvBill.Rows(i).Cells("ClmTotal").Value()
            Next

        Catch ex As Exception
            MsgBox(ex.Message)
            Logger.logException("Operations ", "GetTotalSum ", ex.Message)
        End Try
        Return sum
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.