.NET中自己构建一个ArrDictionary

以下是ArrDictionary类:
Public Class ArrDictionary
Private objCollection As New Collection
Private objDic As New DictionaryEntry
Private strKey, strValue As String
Public i As Integer

Public Function Item(ByVal Index As Integer) As Object
Try
Item = objCollection.Item(Index)
Catch ex As Exception
Item = "错误,无此项!"
End Try
End Function

Public Function Item(ByVal Key As String) As Object
Try
Item = objCollection.Item(Key)
Catch ex As Exception
Item = "错误,无此项!"
End Try
End Function

Public Sub Add(ByVal Key As String, ByVal Value As String)
objDic.Key = Key
objDic.Value = Value
objCollection.Add(objDic, objDic.Key)
i += 1
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
objCollection = Nothing
objDic = Nothing
strKey = ""
strValue = ""
i = 0
End Sub
End Class


以下是调用代码段:
Dim arrSQL As New ArrDictionary

arrSQL.Add("收件号", objExcelSheet.Cells(t, 1).Value)
arrSQL.Add("房屋地址", objExcelSheet.Cells(t, 2).Value)
arrSQL.Add("建筑面积", objExcelSheet.Cells(t, 3).Value)
arrSQL.Add("房型", objExcelSheet.Cells(t, 4).Value)
arrSQL.Add("朝向", objExcelSheet.Cells(t, 5).Value)
arrSQL.Add("楼层", objExcelSheet.Cells(t, 6).Value)
arrSQL.Add("产别", objExcelSheet.Cells(t, 7).Value)
arrSQL.Add("金额", objExcelSheet.Cells(t, 8).Value)
arrSQL.Add("区域", objExcelSheet.Cells(t, 9).Value)
arrSQL.Add("竣工日期", objExcelSheet.Cells(t, 10).Value)
arrSQL.Add("使用年限", objExcelSheet.Cells(t, 11).Value)
arrSQL.Add("联系人", objExcelSheet.Cells(t, 12).Value)
arrSQL.Add("录入人", objExcelSheet.Cells(t, 13).Value)
arrSQL.Add("录入日期", objExcelSheet.Cells(t, 14).Value)
arrSQL.Add("所属分店", objExcelSheet.Cells(t, 15).Value)

'组合字段名
Dim ColumnSQL As String
'组合字段值
Dim ValueSQL As String

For i As Integer = 1 To arrSQL.i
ColumnSQL += arrSQL.Item(i).Key.ToString & ","
ValueSQL += "'" & arrSQL.Item(i).Value.ToString & "',"
Next

'组合SQL语句
objCom.CommandText = "insert into content(" & ColumnSQL & ")" & _
"values(" & ValueSQL & ")"

ColumnSQL = ""
ValueSQL = ""
arrSQL = Nothing


Published At
Categories with Web编程
Tagged with
comments powered by Disqus