Net-informations.com
SiteMap  | About    

how many tables exist in a database - VB.NET

A table is responsible for storing data in the database. A table is a set of data elements that is organized using a model of vertical columns and horizontal rows.A database is made up of many linked tables of rows and columns, each containing specific data.

In many situations you should find the no. of tables exist in your database. Everything about your SQL Server database is stored in its system tables.

  Select DISTINCT(name) FROM sys.Tables

Returns a row for each table object, currently only with sys.objects.type = U. System tables should not be altered directly by any user




Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim command As SqlCommand
        Dim adapter As New SqlDataAdapter
        Dim ds As New DataSet
        Dim tables As DataTable
        Dim i As Integer
        Dim sql As String

        connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
        sql = "Select DISTINCT(name) FROM sys.Tables"
        connection = New SqlConnection(connetionString)

        Try
            connection.Open()
            command = New SqlCommand(sql, connection)
            adapter.SelectCommand = command
            adapter.Fill(ds)
            adapter.Dispose()
            command.Dispose()
            connection.Close()

            For i = 0 To ds.Tables(0).Rows.Count - 1
                MsgBox(ds.Tables(0).Rows(i).Item(0))
            Next

        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try
    End Sub
End Class






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.