Home > Net >  Vb.net, the type of data in the DataTable, how to make data in computing
Vb.net, the type of data in the DataTable, how to make data in computing

Time:09-21

Vb.net how to carry on the calculation using the data in the DataTable



For example,
If the Cell (SimplyCell (I). NodeIndex). Type="ZSZ" Then

ZszXH=GetZszIndex (Cell (SimplyCell (I). NodeIndex). The Name)
H (I)=Zsz (ZszXH) ActGY * 102
C (I)=Zsz (ZszXH) ActQ '//- SimplyCell [I] SimplyNodeQ; '//- Zsz [ZszXH] ActZc;

In the code ActGY is I in the table "actual stand pressure (MPa)"
ActQ is I in the table "actual station displacement (m ^ 3/d)"


Calculation of the code is written in a module
Create a DataTable code is written in this window class
Whether can call the inside of the window class data in the calculation module?

Thank you all!!!

CodePudding user response:

Sometimes the problem isn't difficult, but let a person look not to understand the title of the expression...

Want to use the module calculation method to calculate the value, the dataTable to calculate in the form of byRef code! Done, write a datatable, the interface will automatically change, if it has, under the refresh also had,

CodePudding user response:

The value in the form of parameters passed in no?

CodePudding user response:

Did your datatable binding data sources, if the binding, you want to update the data source, or a refresh it back again,

Whether can call the inside of the window class data in the calculation module? Can you change the modifer attributes of the control to the Public, such as Form1. DataTable1

CodePudding user response:

I write so
Private Sub cmdDBInput_Click (sender As Object, As EventArgs e) Handles cmdDBInput. Click
,,,,,,,,
For I=0 To ZszNum - 1
For j=0 To switchable viewer Tables (0). The Rows. The Count - 1
If t=switchable viewer. Tables (0). The Rows (j). The Item (" RQ ") Then
If switchable viewer. Tables (0). The Rows (j). The Item (" ZM ")=aa. Rows (I) (0) Then
Aa. Rows (I) (1)=switchable viewer. Tables (0). The Rows (j). The Item (" RCKSL ")
Aa. Rows (I) (2)=switchable viewer. Tables (0). The Rows (j). The Item (" GY ")
End the If
End the If
Next
Next
The switchable viewer is my data table, aa is my to extract the data needed to build the DataTable
The aa here. Rows (I) (1) is my calculation of Zsz (I). ActQ
Aa. Rows (I) (2) is my calculation of Zsz (I). ActGY
How to come out in the form of parameters

CodePudding user response:

With a DataColumn. Expression.
Is the aggregation of columns, like Excel formula usage.

 Private Sub CalcColumns () 
Dim rate As Single=. 0862
Dim table As New DataTable ()

'Create the first column.
Dim priceColumn As New DataColumn ()
With priceColumn
. The DataType=System. The GetType (" System. A Decimal ")
The ColumnName="price"
The DefaultValue=https://bbs.csdn.net/topics/50
End With

'Create the second, calculated, column.
Dim taxColumn As New DataColumn ()
With taxColumn
. The DataType=System. The GetType (" System. A Decimal ")
The ColumnName="tax"
The Expression="price * 0.0862"
End With

'Create third column
Dim totalColumn As New DataColumn ()
With totalColumn
. The DataType=System. The GetType (" System. A Decimal ")
The ColumnName="total"
The Expression="price + tax"
End With

'Add columns to the DataTable
With the table. The Columns
The Add (priceColumn)
The Add (taxColumn)
The Add (totalColumn)
End With

Dim row As DataRow=table. NewRow
A table. Rows. The Add (row)
Dim view As New DataView
The Table=Table
DataGrid1. The DataSource=view
End Sub


DataColumn. Expression attribute (System. Data) | Microsoft Docs
https://docs.microsoft.com/zh-cn/dotnet/api/system.data.datacolumn.expression? View=netframework 4.8

CodePudding user response:

The
refer to the original poster weixin_45823259 response:
vb.net how to use the data in the DataTable calculated



For example,
If the Cell (SimplyCell (I). NodeIndex). Type="ZSZ" Then

ZszXH=GetZszIndex (Cell (SimplyCell (I). NodeIndex). The Name)
H (I)=Zsz (ZszXH) ActGY * 102
C (I)=Zsz (ZszXH) ActQ '//- SimplyCell [I] SimplyNodeQ; '//- Zsz [ZszXH] ActZc;

In the code ActGY is I in the table "actual stand pressure (MPa)"
ActQ is I in the table "actual station displacement (m ^ 3/d)"


Calculation of the code is written in a module
Create a DataTable code is written in this window class
Whether can call the inside of the window class data in the calculation module?

Thank you all!!!


Contain first datatable form open not new, but direct call form name, form1. Show
In the form of code defines a public class data table, used to store your data, calculation of other modules you need to call this form of data tables directly call line,

CodePudding user response:

Write a foreach loop read datatable, in a loop and calculated values, efficiency is higher, or recommended weixin_45823259 said has a solution.