System.NullReferenceException:“未將物件參考設定到物件的實體。”
Public Class FormZsz
Public Sub cmdDBInput_Click(sender As Object, e As EventArgs) Handles cmdDBInput.Click
、、、、、
DataGridView1.DataSource = aa

如何將DataGridView中第二列的資料賦給下面代碼中的ActQ
Module ModuleCalculation
、、、、、、、、、、、、
If Cell(SimplyCell(i).NodeIndex).Type = "zsz" Then
ZszXH = GetZszIndex(Cell(SimplyCell(i).NodeIndex).Name)
H(i) = Zsz(ZszXH).ActGY * 102
C(i) = Zsz(ZszXH).ActQ
uj5u.com熱心網友回復:
https://blog.csdn.net/hejisan/article/details/52688972uj5u.com熱心網友回復:
datagridview.rows(i).cells(p).valueuj5u.com熱心網友回復:
我這其中一個是Class一個是Moudle
直接這么寫
Zsz(i).ActQ=DataGridView1.Rows(i).Cells(1).Value
出現錯誤
uj5u.com熱心網友回復:
檢測你的I的值,確保rows(i)和asz(i) isnot nothinguj5u.com熱心網友回復:

錯誤是這樣的,應該還是傳參的錯誤?
uj5u.com熱心網友回復:
偷懶點就把datagridview傳過去唄。public function 計算(byval dgv as datagridview,其他引數) AS double
Zsz(i).ActQ=dgv.Rows(i).Cells(1).Value
end function
class里呼叫
DIM P AS DOUBLE = 計算(DATAGRIDVIEW1,其他引數)
uj5u.com熱心網友回復:
為何從datagridview中拿?系結的資料源里拿出來,不是更好嗎?
除非你這個是前臺寫上去的。
那么你要找到對應的rows和cells
uj5u.com熱心網友回復:
因為我這個資料源涉及到生產日期,我需要提取某一個生產日期的資料進行計算,所以我第一步將有用的資料提取出來了,然后需要用這些資料進行計算uj5u.com熱心網友回復:
很難理解他們到底要干什么.....資料庫里取值的話,再sql階段就可以把資料算好了。
dataTable階段創建個計算列也完事兒了。
不創建計算列,來個For回圈計算比較復雜的運算。
--
視乎要把計算單獨做成dll,可以更新演算法??
反正,不怎么好理解。
uj5u.com熱心網友回復:
在你的另外一個帖子中已經恢復了.再回復一遍會不會給雙份積分?
先上例程,
Private Sub CalcColumns()
Dim rate As Single = .0862
Dim table As New DataTable()
' Create the first column.
Dim priceColumn As New DataColumn()
With priceColumn
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "price"
.DefaultValue = 50
End With
' Create the second, calculated, column.
Dim taxColumn As New DataColumn()
With taxColumn
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "tax"
.Expression = "price * 0.0862"
End With
' Create third column
Dim totalColumn As New DataColumn()
With totalColumn
.DataType = System.Type.GetType("System.Decimal")
.ColumnName = "total"
.Expression = "price + tax"
End With
' Add columns to DataTable
With table.Columns
.Add(priceColumn)
.Add(taxColumn)
.Add(totalColumn)
End With
Dim row As DataRow= table.NewRow
table.Rows.Add(row)
Dim view As New DataView
view.Table = table
DataGrid1.DataSource = view
End Sub
實作,主要用到 DataColumn.Expression屬性.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/77819.html
標籤:VB.NET
