·您的位置: 首页 » 资源教程 » 编程开发 » ASP.NET » .NET中自己构建一个ArrDictionary

.NET中自己构建一个ArrDictionary

类别: ASP.NET教程  评论数:0 总得分:0

以下是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




-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1