Results 1 to 6 of 6

Thread: SQL Table Informations

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Smile SQL Table Informations

    'This code will display the SQL Table Information
    Code:
    'Global declartion
    Imports System.Data
    Imports System.Data.SqlClient
    
    'In a Form
    'Add one command button and name it as Button2
    'Add one Dropdownbox and name it as cmbTablenames
    'Add one DataGridview control
    'And in the command button click event add this code
    
     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Try
                Dim con As New SqlConnection("User ID=sa;pwd=secreate;Initial Catalog=YourDatabaseName;Data Source=SQLSERVERNAME")
                Dim SchemaAdapter As New SqlDataAdapter("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME", con)
                con.Open()
                Dim Schematable As New DataTable
                SchemaAdapter.Fill(Schematable)
                Dim i As Long
                For i = 1 To Schematable.Rows.Count - 1
                    cmbTablenames.Items.Add(Schematable.Rows(i).Item("TABLE_NAME").ToString) 'add the tablenames
                Next
                Schematable.Dispose()
                con.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    
    'FUNCTION TO DISPLAY THE TABLE INFORMATION WITH RESPECT TO TABLENAME
     Private Sub DisplayTableInformation(ByVal tablename As String)
            Try
    
                'Function to display the table information
                'Add a datagridview control
                Dim con As New SqlConnection"User ID=sa;pwd=secreate;Initial Catalog=YourDatabaseName;Data Source=SQLSERVERNAME")
                Dim SQL As String
                SQL = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" & tablename & "'"
                Dim SchemaAdapter As New SqlDataAdapter(SQL, con)
                con.Open()
                Dim Schematable As New DataTable
                SchemaAdapter.Fill(Schematable)
                DataGridView1.DataSource = Schematable
                 Schematable.Dispose()
                con.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    'In the DropDownBox Change event add this code
    Private Sub cmbTablenames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTablenames.SelectedIndexChanged
            DisplayTableInformation(cmbTablenames.Text)
        End Sub
    Last edited by danasegarane; Feb 27th, 2007 at 11:14 PM.
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Exclamation Re: SQL Table Informations

    i follow the above codes and got this error:
    Compiler Error Message: BC30519: Overload resolution failed because no accessible 'New' can be called without a narrowing conversion

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: SQL Table Informations

    It is working For me.Can you highlight the line Where you got the error?
    Please mark you thread resolved using the Thread Tools as shown

  4. #4
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Exclamation Re: SQL Table Informations

    the code can work..
    but is it possible to list the data of the table???
    What i got now is all the table properities eg:
    TABLE_CATALOG:mydb
    TABLE_SCHEMA:dbo
    TABLE_NAME:customer
    the above is what got after using the codes.....which is not i want..
    what i want is the data like in customer table there are 3 column:
    name, contact, status
    so the page should display name, contact and status with all the data in the respective column

  5. #5

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: SQL Table Informations

    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    New Member
    Join Date
    Jan 2008
    Posts
    14

    Resolved Re: SQL Table Informations

    hi danasegarane
    Thank you for your nice and helpfull code.
    That really work good and help me a lot
    again thanks
    i am so lucky that find this tread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width