如何使用vb.net检查表在特定数据库中是否存在 [英] how to check if table exists in particular database using vb.net

查看:92
本文介绍了如何使用vb.net检查表在特定数据库中是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我正确的密码...

pls send me a correct code...

con = New SqlConnection("Data Source=Localhost;Initial Catalog=master;User ID=sa;Password=sa;")
        con.Open()
        cmd = New SqlCommand("select * from dbo.sysobjects where id = object_id('[dbo].[sss]')", con)
        Dim bRet As Boolean = False
        Dim reader As SqlDataReader = cmd.ExecuteReader
        bRet = reader.HasRows
        If (bRet = False) Then
            MsgBox("Table Exists")
        Else
            MsgBox("No more records")
        End If

推荐答案

在sql中执行此操作:

Do this in sql:

USE [DatabaseName]; -- Replace [DatabaseName] with the name of your database
SELECT COUNT(table_name) FROM INFORMATION_SCHEMA.Tables -- the keyword table_name here is fixed



从那里,您现在可以在VB.NET代码中操作结果,如果结果大于0,则该表存在.

问候,
爱德华



From there, you can now manipulate the result in VB.NET code that if result is greater than 0, then the table exists.

Regards,
Eduard


这篇关于如何使用vb.net检查表在特定数据库中是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆