vb.net 获取数据表 字段名和数据类型

来源:互联网 发布:做淘宝如何找货源 编辑:程序博客网 时间:2024/06/04 20:09

  '根据表名或 表'获取表中 除图片类型外的字段名
    Public Function GetTableFields(ByVal tbname As String) As DataView
        If tbname = "" Then
            MsgBox("请输入参数:表名")
            Exit Function
        End If
        Dim strsql As String
        strsql = "select COLUMN_NAME as [字段名],DATA_TYPE   "
        strsql += "FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME='" + tbname + "' and  DATA_TYPE<>'image'"
        Dim db As New DataBase
        Dim dv As New DataView
        Dim i As Integer
        Try
            dv = db.RunSelectSQL(strsql)
            Return dv
        Catch ex As Exception
            MsgBox(ex.Message + vbCrLf + ex.StackTrace)
            Return Nothing
        Finally
            db.Dispose()
            dv.Dispose()
        End Try

说明: database 是自己定义的一个数据通用 类

原创粉丝点击