Select Columns names from a table.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Select Columns names from a table.

  1. #1
    Faisal Guest

    Select Columns names from a table.


    Hello Friends..

    How can we get the column names from a table in Oracle as well as from SQL
    Server db.
    Is there any sql functions or procedures to do it..
    Pls any help...

    Thanks in advance..
    Faisal


  2. #2
    Bernie Guest

    Re: Select Columns names from a table.


    "Faisal" <fasmohd00@hotmail.com> wrote:
    >
    >Hello Friends..
    >
    >How can we get the column names from a table in Oracle as well as from SQL
    >Server db.
    >Is there any sql functions or procedures to do it..
    >Pls any help...
    >
    >Thanks in advance..
    >Faisal
    >


    Hi

    The simpliest way is to use ADOX but you can use ADO as well. Open a Recordset
    like SELECT * FROM MyTable WHERE 1=2 (you don't need to get any records for
    this) and scroll through the Fields collection. Each Field has allways a
    Name property. Type and Precision are other useful properties...

    Bernie

  3. #3
    Michael Culley Guest

    Re: Select Columns names from a table.

    For SQL Server:

    SELECT dbo.syscolumns.name AS ColName
    FROM dbo.syscolumns INNER JOIN
    dbo.sysobjects ON dbo.syscolumns.id =
    dbo.sysobjects.id
    WHERE (dbo.sysobjects.name = N'MyTableName')

    --
    Michael Culley
    www.vbdotcom.com


    "Bernie" <magnus.bernroth@rejlers.se> wrote in message
    news:3c70c3a5$1@10.1.10.29...
    >
    > "Faisal" <fasmohd00@hotmail.com> wrote:
    > >
    > >Hello Friends..
    > >
    > >How can we get the column names from a table in Oracle as well as from

    SQL
    > >Server db.
    > >Is there any sql functions or procedures to do it..
    > >Pls any help...
    > >
    > >Thanks in advance..
    > >Faisal
    > >

    >
    > Hi
    >
    > The simpliest way is to use ADOX but you can use ADO as well. Open a

    Recordset
    > like SELECT * FROM MyTable WHERE 1=2 (you don't need to get any records

    for
    > this) and scroll through the Fields collection. Each Field has allways a
    > Name property. Type and Precision are other useful properties...
    >
    > Bernie




  4. #4
    Faisal Guest

    Re: Select Columns names from a table.


    Hei Friends,
    Thanks for ur help..
    I succeded the same using ADO.
    My code is as
    -----------------
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim fld As ADODB.Field
    Dim prop As ADODB.Property

    Dim strCon As String

    strCon = "DSN=" & txtDsn & ";Uid=" & txtUid & ";pwd=" & txtPwd & ";"

    On Error GoTo ErrDB
    Set con = New ADODB.Connection
    Set rs = New ADODB.Recordset
    con.Open strCon
    rs.Open Trim(txtTable), con, , , adCmdTable
    For Each fld In rs.Fields
    print fld.Name
    Next

    rs.Close
    con.Close
    Set rs = Nothing
    Set con = Nothing
    loadColumns = True
    Exit Function
    ErrDB:
    If Err.Number = -2147217865 Then
    MsgBox "Table doesnot exist", vbCritical + vbOKOnly, "Invalid Table
    Name"
    loadColumns = False
    Exit Function
    End If

    ---------------------
    Regards
    Faisal

    "Michael Culley" <mike@vbdotcom.com> wrote:
    >For SQL Server:
    >
    >SELECT dbo.syscolumns.name AS ColName
    >FROM dbo.syscolumns INNER JOIN
    > dbo.sysobjects ON dbo.syscolumns.id =
    >dbo.sysobjects.id
    >WHERE (dbo.sysobjects.name = N'MyTableName')
    >
    >--
    >Michael Culley
    >www.vbdotcom.com
    >
    >
    >"Bernie" <magnus.bernroth@rejlers.se> wrote in message
    >news:3c70c3a5$1@10.1.10.29...
    >>
    >> "Faisal" <fasmohd00@hotmail.com> wrote:
    >> >
    >> >Hello Friends..
    >> >
    >> >How can we get the column names from a table in Oracle as well as from

    >SQL
    >> >Server db.
    >> >Is there any sql functions or procedures to do it..
    >> >Pls any help...
    >> >
    >> >Thanks in advance..
    >> >Faisal
    >> >

    >>
    >> Hi
    >>
    >> The simpliest way is to use ADOX but you can use ADO as well. Open a

    >Recordset
    >> like SELECT * FROM MyTable WHERE 1=2 (you don't need to get any records

    >for
    >> this) and scroll through the Fields collection. Each Field has allways

    a
    >> Name property. Type and Precision are other useful properties...
    >>
    >> Bernie

    >
    >



  5. #5
    Michael Culley Guest

    Re: Select Columns names from a table.

    >> MsgBox "Table doesnot exist", vbCritical + vbOKOnly, "Invalid Table

    As a general rule 'or' should be used instead of +

    --
    Michael Culley
    www.vbdotcom.com


    "Faisal" <fasmohd00@hotmail.com> wrote in message
    news:3c71cf6f$1@10.1.10.29...
    >
    > Hei Friends,
    > Thanks for ur help..
    > I succeded the same using ADO.
    > My code is as
    > -----------------
    > Dim con As ADODB.Connection
    > Dim rs As ADODB.Recordset
    > Dim fld As ADODB.Field
    > Dim prop As ADODB.Property
    >
    > Dim strCon As String
    >
    > strCon = "DSN=" & txtDsn & ";Uid=" & txtUid & ";pwd=" & txtPwd & ";"
    >
    > On Error GoTo ErrDB
    > Set con = New ADODB.Connection
    > Set rs = New ADODB.Recordset
    > con.Open strCon
    > rs.Open Trim(txtTable), con, , , adCmdTable
    > For Each fld In rs.Fields
    > print fld.Name
    > Next
    >
    > rs.Close
    > con.Close
    > Set rs = Nothing
    > Set con = Nothing
    > loadColumns = True
    > Exit Function
    > ErrDB:
    > If Err.Number = -2147217865 Then
    > MsgBox "Table doesnot exist", vbCritical + vbOKOnly, "Invalid

    Table
    > Name"
    > loadColumns = False
    > Exit Function
    > End If
    >
    > ---------------------
    > Regards
    > Faisal
    >
    > "Michael Culley" <mike@vbdotcom.com> wrote:
    > >For SQL Server:
    > >
    > >SELECT dbo.syscolumns.name AS ColName
    > >FROM dbo.syscolumns INNER JOIN
    > > dbo.sysobjects ON dbo.syscolumns.id =
    > >dbo.sysobjects.id
    > >WHERE (dbo.sysobjects.name = N'MyTableName')
    > >
    > >--
    > >Michael Culley
    > >www.vbdotcom.com
    > >
    > >
    > >"Bernie" <magnus.bernroth@rejlers.se> wrote in message
    > >news:3c70c3a5$1@10.1.10.29...
    > >>
    > >> "Faisal" <fasmohd00@hotmail.com> wrote:
    > >> >
    > >> >Hello Friends..
    > >> >
    > >> >How can we get the column names from a table in Oracle as well as from

    > >SQL
    > >> >Server db.
    > >> >Is there any sql functions or procedures to do it..
    > >> >Pls any help...
    > >> >
    > >> >Thanks in advance..
    > >> >Faisal
    > >> >
    > >>
    > >> Hi
    > >>
    > >> The simpliest way is to use ADOX but you can use ADO as well. Open a

    > >Recordset
    > >> like SELECT * FROM MyTable WHERE 1=2 (you don't need to get any records

    > >for
    > >> this) and scroll through the Fields collection. Each Field has allways

    > a
    > >> Name property. Type and Precision are other useful properties...
    > >>
    > >> Bernie

    > >
    > >

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center