当前位置: 代码迷 >> VB Dotnet >> 关于VB.Net判断数据库表内是否存在某字段解决思路
  详细解决方案

关于VB.Net判断数据库表内是否存在某字段解决思路

热度:361   发布时间:2016-04-25 02:24:11.0
关于VB.Net判断数据库表内是否存在某字段
VB.net 如何去判断一个数据库表中是否存在某字段? 比如是否存在ID字段?

------解决方案--------------------
查询 sysobjects 表
------解决方案--------------------
  Function IsColExisted(ByVal conSource_ As SqlConnection, ByVal strTableName_ As String, ByVal strColName_ As String) As Boolean
        Dim bExist As Boolean = False
        Dim strExist As String
        Dim nNum As Integer
        strExist = "select count(*) from dbo.syscolumns where id=object_id('" + strTableName_ + "')" + " and name='" + strColName_ + "'"
        Dim cmdExist As SqlCommand = New SqlCommand(strExist, conSource_)
        nNum = cmdExist.ExecuteScalar
        If (nNum <> 0) Then
            bExist = True
        Else
            bExist = False
        End If
        Return bExist
    End Function
  相关解决方案