Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Retrieving Column Comments with vb.net

AsakerJul 7 2011 — edited Jul 9 2011
Hi All

I'm here asking one practical issue which faced me and it may face alot of you

the Issue started when I'm was thing to develop an application in VB .net which will handle counters operations in one of the public sector, thus I had created a table to Store Counter Information Like this


CREATE TABLE COUNTERS.CNT_SETTINGS
(
CNT_STG_NO VARCHAR2(2 BYTE) NOT NULL,
CNT_STG_IP VARCHAR2(15 BYTE),
CNT_STG_REG VARCHAR2(1 BYTE),
CNT_STG_SERV VARCHAR2(1 BYTE) DEFAULT 'A',
CNT_STG_TOKEN VARCHAR2(1 BYTE)
);

COMMENT ON COLUMN COUNTERS.CNT_SETTINGS.CNT_STG_NO IS 'Counter No';
COMMENT ON COLUMN COUNTERS.CNT_SETTINGS.CNT_STG_IP IS 'Counter IP Address';
COMMENT ON COLUMN COUNTERS.CNT_SETTINGS.CNT_STG_REG IS 'Counter Registered (Y/N)';
COMMENT ON COLUMN COUNTERS.CNT_SETTINGS.CNT_STG_SERV IS 'Type of Services (A - All / S - Selected)';
COMMENT ON COLUMN COUNTERS.CNT_SETTINGS.CNT_STG_TOKEN IS 'Counter Has Token (Y/N)';

CREATE UNIQUE INDEX COUNTERS.CNTSTG_NO_PK1 ON COUNTERS.CNT_SETTINGS
(CNT_STG_NO);

ALTER TABLE COUNTERS.CNT_SETTINGS ADD (
CHECK (CNT_STG_REG IN ('Y','N')));
ALTER TABLE COUNTERS.CNT_SETTINGS ADD (
CHECK (CNT_STG_SERV IN ('A','S')));
ALTER TABLE COUNTERS.CNT_SETTINGS ADD (
CHECK (CNT_STG_TOKEN IN ('Y','N')));

ALTER TABLE COUNTERS.CNT_SETTINGS ADD (
CONSTRAINT CNTSTG_NO_PK1
PRIMARY KEY
(CNT_STG_NO)

Now when I Created a project in VB.net and I would like to populate that table and show it in DataGridView

The DataGridView is showing me the Columns names as they are created in Oracle (CNT_STG_NO ,CNT_STG_IP , ... etc)

But I need a way where I retrieve a Comments inserted earlier in oracle and submit it as column header text.

Honstly I found one way to do so but without depending on Comments from Oracle Side I did somethiong like Caption of the Column

VB .net Code
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Imports Oracle.DataAccess.Client

Public Class FRM_Settings
Dim counters_conn As New OracleConnection(FRM_LOG_IN.ORACONNECTIONSTRING)
Dim tokens_conn As New OracleConnection(FRM_LOG_IN.ORACONNECTIONSTRING)
Dim counters_ds As New DataSet("counter_dS")
Dim counters_tbl As New DataTable("counters_settings")
Dim tokens_tbl As New DataTable("tokens_settings")
Dim cmdcounters As OracleCommand
Dim cmdtokens As OracleCommand


Private Sub FRM_Settings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Me.Counters_DGV.ReadOnly = True
Me.Cursor = Cursors.Default
Me.TabCounters.Cursor = Cursors.Default
Me.TabCount.Cursor = Cursors.Default

counters_ds.Tables.Add(counters_tbl)
counters_ds.Tables.Add(tokens_tbl)

cmdcounters = New OracleCommand("SELECT CNT_STG_NO, CNT_STG_IP, CNT_STG_REG, " & _
" CNT_STG_SERV, CNT_STG_TOKEN from cnt_settings ", counters_conn)

Dim cnt_adp As New OracleDataAdapter(cmdcounters)

cnt_adp.Fill(counters_ds.Tables("counters_settings"))

counters_tbl.Columns("CNT_STG_NO").Caption = "Counter No"
counters_tbl.Columns("CNT_STG_IP").Caption = "IP Address "
counters_tbl.Columns("CNT_STG_REG").Caption = "Registered ? (Y/N)"
counters_tbl.Columns("CNT_STG_SERV").Caption = "Service Type (A-All / S-Selected"
counters_tbl.Columns("CNT_STG_TOKEN").Caption = "Has Token ? (Y/N)"

counters_tbl.Columns("cnt_stg_ip").Unique = True

Counters_DGV.DataSource = counters_ds.Tables("counters_settings")

For col As Integer = 0 To counters_tbl.Columns.Count - 1
Counters_DGV.Columns(col).HeaderText = counters_tbl.Columns(col).Caption
Next

Counters_DGV.Refresh()

Catch oraex As OracleException
MessageBox.Show(oraex.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Disposing
End Try
End Sub
End Class



Now I do not need to practice this in the future and I would like to stick with Retrieving Column Comments from Database side

Any Idea's????


Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2011
Added on Jul 7 2011
4 comments
513 views