Results 1 to 11 of 11

Thread: [RESOLVED] List table value

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Resolved [RESOLVED] List table value

    i have a few tables in my database and all their field names are different.. is it possible to display out the data in the tables selected by the users into 1aspx page??
    Eg: the database have the following tables;
    customers
    staff
    inventory
    when the user selected the 'customers' tables all the information inside the tables will be display...

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

    Re: List table value

    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Exclamation Re: List table value

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

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

    Re: List table value

    It is working for me.Can you point the line where you got the Error?
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Exclamation Re: List table value

    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 what 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
    Last edited by bczm8703; Mar 6th, 2007 at 11:05 PM.

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

    Re: List table value

    Change the sql in the function "DisplayTableInformation" as follows.
    vb Code:
    1. SQL = "SELECT * FROM TABLE_NAME ='" & tablename & "'"

    Now this will display all the columns in the table
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Exclamation Re: List table value

    but now i got
    System.Data.OleDb.OleDbException: Line 1: Incorrect syntax near '='.
    Source Error:
    Line 66: schemaAdapter.Fill(Schematable)


    my code is
    Code:
    SQL = "SELECT * FROM TABLE_NAME ='" & tablename & "'"
    
            command = New OleDbCommand(SQL, con)
            schemaAdapter = New OleDbDataAdapter(command)
            con.Open()
            Dim Schematable As New DataTable
            schemaAdapter.Fill(Schematable)
    thanks for taking your time to help....

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

    Re: List table value

    Ok Here is the fullcode
    vb Code:
    1. Imports System.Data
    2. Imports System.Data.SqlClient
    3.  
    4. Public Class Form1
    5.  
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         Try
    8.             cmbtableNames.DisplayMember = "Text"
    9.             Dim con As New SqlConnection("User ID=sa;pwd=secrate;Initial Catalog=Mydb;Data Source=customer")
    10.             Dim SchemaAdapter As New SqlDataAdapter("SELECT table_name,table_Schema FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME", con)
    11.             con.Open()
    12.             Dim Schematable As New DataTable
    13.             SchemaAdapter.Fill(Schematable)
    14.             Dim i As Long
    15.             For i = 1 To Schematable.Rows.Count - 1
    16.                 'cmbtableNames.Items.Add(Schematable.Rows(i).Item("TABLE_NAME").ToString) 'add the tablenames
    17.                 cmbtableNames.Items.Add(New MyItem(Schematable.Rows(i).Item("TABLE_NAME").ToString, Schematable.Rows(i).Item("table_Schema").ToString))
    18.             Next
    19.             Schematable.Dispose()
    20.             con.Close()
    21.         Catch ex As Exception
    22.             MessageBox.Show(ex.Message)
    23.         End Try
    24.  
    25.     End Sub
    26.     'FUNCTION TO DISPLAY THE TABLE INFORMATION WITH RESPECT TO TABLENAME
    27.     Private Sub DisplayTableInformation(ByVal tablename As String, ByVal owner As String)
    28.         Try
    29.  
    30.             'Function to display the table information
    31.             'Add a datagridview control
    32.             Dim con As New SqlConnection("User ID=sa;pwd=secrate;Initial Catalog=Mydb;Data Source=customer")
    33.             Dim SQL As String
    34.             'SQL = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='" & tablename & "'"
    35.             SQL = "SELECT * FROM " & owner & "." & tablename
    36.             Dim SchemaAdapter As New SqlDataAdapter(SQL, con)
    37.             con.Open()
    38.             Dim Schematable As New DataTable
    39.             'Dim Schematable As New DataSet
    40.             SchemaAdapter.Fill(Schematable)
    41.             SchemaAdapter.Fill(Schematable)
    42.             DataGridView1.DataSource = Schematable
    43.             Schematable.Dispose()
    44.             con.Close()
    45.         Catch ex As Exception
    46.             MessageBox.Show(ex.Message)
    47.         End Try
    48.  
    49.     End Sub
    50.     Private Sub cmbTablenames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbtableNames.SelectedIndexChanged
    51.         'declare a copy of your subclass
    52.         Dim AnItem As MyItem
    53.         'cast the incoming node into your subclass
    54.         AnItem = CType(cmbtableNames.SelectedItem, MyItem)
    55.         DisplayTableInformation(cmbtableNames.Text, AnItem.MyStrng)
    56.     End Sub
    57.     Class MyItem
    58.         'Since all we need is a "Text" property for this example we can
    59.         'Subclass by inheriting any object desired.
    60.         'For this example, we'll use the ListViewItem
    61.         Inherits ListViewItem
    62.         'each of the below public declarations will be "visible" to the outside
    63.         'You may add as many of these declarations using whatever types you desire
    64.         Public MyShowText As String
    65.         Public MyStrng As String
    66.         'every value of MyInfo you want to store, get's added to the NEW declaration
    67.         Sub New(ByVal ShowText As String, ByVal Strng As String)
    68.             MyBase.New()
    69.             'transfer all incoming parameters to your local storage
    70.             MyShowText = ShowText
    71.             MyStrng = Strng
    72.             'and finally, pass back the Text property
    73.             Me.Text = MyShowText
    74.         End Sub
    75.     End Class
    76.  
    77. End Class
    Last edited by danasegarane; Mar 7th, 2007 at 01:05 AM.
    Please mark you thread resolved using the Thread Tools as shown

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    118

    Talking Re: List table value

    million thanks.... it is working....

    thanks for ur time and help

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

    Re: List table value

    Welcome
    vb Code:
    1. If u have your answer please go to the thread tools and click "Mark Thread Resolved"
    2. If this post has helped you please rate it by clicking the scales to the left of this post!
    Please mark you thread resolved using the Thread Tools as shown

  11. #11
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: [RESOLVED] List table value

    It's nice...It helps me...

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