定义一操作数据库中物理表的类CData,此类继承CDataBase,即:
| Public Class CData:Inherits CDataBase |
| '所要操作的表名 Private Shared UpdateTableName As String '所要操作的表对象 Public Shared UpdateDataTable As New DataTable() '对应表的一行数据197 Public Shared ObjFields() As Object '表的字段数 Public Shared FieldCount As Int16 '主关键字。我们假设每个物理表都有一个主关键字字段fSystemID Public Shared SystemID As String |
| Public Property UpdateTable() As String Get UpdateTable = UpdateTableName End Get Set(ByVal Value As String) UpdateTableName = Value.Trim UpdateDataTable = DB.GetDataTable(UpdateTableName) UpdateTableFieldNames = UpdateDataTable.Clone FieldCount = UpdateDataTable.Columns.Count ReDim ObjFields(FieldCount - 1) End Set End Property '删除由主关键值fSystemID指定的数据行 Public Sub Delete() Dim strSQL As String strSQL = "Delete from " & UpdateTableName & " where fSystemID=" & SystemID DB.Delete(strSQL) UpdateDataTable.Rows.Remove(GetRow) End Sub '向表UpdateTableName中插入一行数据。数据由ObjFields给出 Public Function Insert() As Boolean DB.Insert(UpdateTableName, ObjFields) End Function '更新表UpdateTableName所指定的行 Public Shadows Sub Update() Dim SetField As String Dim i As Int16 For i = 1 To FieldCount - 1 SetField = UpdateTableFieldNames.Columns(i).ColumnName & "=" & ObjFields(i) UpdateField(SetField) Next End Sub Public Sub UpdateField(ByVal SetField As String) Dim StrSQL As String StrSQL = "select * from " & UpdateTableName & " where fSystemID= " & SystemID DB.Update(StrSQL, SetField) End Sub '填充网络数据 Public Overloads Sub FillGrid(ByVal GridName As DataGrid) GridName.DataSource = UpdateDataTable End Sub '把数据网格的当前行数据定写入到输入控件中 Public Sub DataGridToText(ByVal frm As Form) Dim RowIndex, i As Int16 Dim value Dim obj As Control Dim DataGrid As New DataGrid() If FieldCount = 0 Then Exit Sub For Each obj In frm.Controls If obj.GetType.Name = "DataGrid" Then DataGrid = obj Exit For End If Next RowIndex = DataGrid.CurrentRowIndex For i = 1 To FieldCount - 1 value = DataGrid.Item(RowIndex, i) If IsDBNull(value) = True Then value = "" End If For Each obj In frm.Controls ' If obj.TabIndex = i Then obj.Text = value Exit For End If Next Next End Sub |
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页