关于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