我开发了一个VB.Net DLL,它可以读取Postgres、Oracle和OleDb。
为了允许这个DLL执行一些SQL命令,我向它传递一个Connection对象,并使用它执行一些SQL SELECT命令。
我现在的问题是,我希望传递包含在GridView对象中的所有数据,该对象包含在EXE程序(而不是在DLL中)中使用SQL命令获得的数据,并且用户可以进行更改。
考虑到以下约束,可以传递哪种类型的对象?
DataGridView (DLL中没有Winform对象)。DataGridView内容填充另一个数据库的表(非表演性)COM,太老了)。到目前为止,找到的唯一解决方案是使用ADO或Microsoft ActiveX Data Object Record Set,但是这个类不是.Net程序集,而在DataBase杂志上找到的解决方案不能工作,因为Field类的Items属性是只读的。
这是我的密码
Dim rstADO As ADODB.Recordset
rstADO = New ADODB.Recordset
With rstADO
.Fields.Append("EmployeeID", ADODB.DataTypeEnum.adInteger, 0, ADODB.FieldAttributeEnum.adFldKeyColumn)
.Fields.Append("FirstName", ADODB.DataTypeEnum.adVarChar, 10, ADODB.FieldAttributeEnum.adFldMayBeNull)
.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.LockType = ADODB.LockTypeEnum.adLockPessimistic
.Open()
For Each row As DataGridViewRow In grid.Rows
.AddNew()
For i = 0 To grid.Columns.Count - 1
.Fields(i) = row.Cells(i).Value
Next i
.Update()
Next row
End With行.Fields(i)在错误BC30526之后取消支付:'Item‘属性为'ReadOnly’。
我可以用哪一门课?
发布于 2022-02-08 19:31:51
我使用了tramex用户提出的解决方案。
我希望提取除Edit et PDF列之外的所有列,并且需要根据DataGridView中的另一列添加一个名为cash的特殊列。
这是我的密码
Dim dt As New DataTable
Dim sName As String
Dim type As Type
Dim oSKipList() As String = {"Edit", "PDF"}
For Each col As DataGridViewColumn In grid.Columns
sName = col.Name.Replace("Col_", "")
If Not oSKipList.Contains(sName) Then
type = col.CellTemplate.FormattedValueType
dt.Columns.Add(sName, type)
End If
Next col
dt.Columns.Add("cash", Type.GetType("System.String"))
For Each row As DataGridViewRow In grid.Rows
Dim dr As DataRow = dt.NewRow
Dim n = 0
For Each col As DataGridViewColumn In grid.Columns
sName = col.Name.Replace("Col_", "")
If Not oSKipList.Contains(sName) Then
Dim i = col.Index
dr(n) = row.Cells(i).Value
n += 1
End If
Next col
dr(n) = IIf(dr("Account") = "-", "CASH", "")
dt.Rows.Add(dr)
Next row
oExcelReport.SetDataTable(dt)此代码的第一部分初始化列,第二部分初始化行。
这段代码在我的程序上运行得很好。
https://stackoverflow.com/questions/71029510
复制相似问题