Oracle Help Needed - ComboBox data binding
-
I am having some difficulty in getting my .NET application to work as desired using an Oracle database (I am using the Oracle Data Provider for .NET). In particular, my ComboBox no longer contains any items. I had a SQL table:
CREATE TABLE [dbo].[tblTitles] ( [TitleID] [int] IDENTITY (1, 1) NOT NULL , [TitleDisplayText] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [TitleHidden] [bit] NULL CONSTRAINT [DF_tblTitles_TitleHidden] DEFAULT (0), CONSTRAINT [PK_Titles] PRIMARY KEY CLUSTERED ( [TitleID] ) ON [PRIMARY] ) ON [PRIMARY]
and created a complementary (I think) Oracle table:CREATE SEQUENCE tblTitles_TitleID_SEQ START WITH 1 INCREMENT BY 1 / CREATE TABLE tblTitles ( TitleID int NOT NULL , TitleDisplayText VARCHAR2 (50) NULL , TitleHidden NUMBER(1) DEFAULT 0 NULL , CONSTRAINT PK_Titles PRIMARY KEY (TitleID) )
My Code (which worked against SQL Server table, but not against Oracle):// Create the dataset DataSet dsTitles = new DataSet("Titles"); OpenConnection(); // creates and opens a new connection or returns existing connection. OracleCommand tableCommand = null; tableCommand = dbConnection.CreateCommand(); tableCommand.CommandText = "select TitleID, TitleDisplayText FROM tblTitles WHERE TitleHidden <> 1 ORDER BY TitleDisplayText"; OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = tableCommand; adapter.Fill(dsTitles, "Titles"); // Bind to ComboBox comboBoxTitle.BeginUpdate(); comboBoxTitle.DataSource = dsTitles.Tables["Titles"]; comboBoxTitle.DisplayMember = "TitleDisplayText"; comboBoxTitle.ValueMember = "TitleID"; comboBoxTitle.EndUpdate();
If I create an OracleDataReader and execute the query, adding each item to the ComboBox, it displays, but this takes a considerable amount of time. Any ideas on what I'm doing wrong, or not doing? If this is not the best place to ask, kindly advise a better place. Thanks, Glenn -
I am having some difficulty in getting my .NET application to work as desired using an Oracle database (I am using the Oracle Data Provider for .NET). In particular, my ComboBox no longer contains any items. I had a SQL table:
CREATE TABLE [dbo].[tblTitles] ( [TitleID] [int] IDENTITY (1, 1) NOT NULL , [TitleDisplayText] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [TitleHidden] [bit] NULL CONSTRAINT [DF_tblTitles_TitleHidden] DEFAULT (0), CONSTRAINT [PK_Titles] PRIMARY KEY CLUSTERED ( [TitleID] ) ON [PRIMARY] ) ON [PRIMARY]
and created a complementary (I think) Oracle table:CREATE SEQUENCE tblTitles_TitleID_SEQ START WITH 1 INCREMENT BY 1 / CREATE TABLE tblTitles ( TitleID int NOT NULL , TitleDisplayText VARCHAR2 (50) NULL , TitleHidden NUMBER(1) DEFAULT 0 NULL , CONSTRAINT PK_Titles PRIMARY KEY (TitleID) )
My Code (which worked against SQL Server table, but not against Oracle):// Create the dataset DataSet dsTitles = new DataSet("Titles"); OpenConnection(); // creates and opens a new connection or returns existing connection. OracleCommand tableCommand = null; tableCommand = dbConnection.CreateCommand(); tableCommand.CommandText = "select TitleID, TitleDisplayText FROM tblTitles WHERE TitleHidden <> 1 ORDER BY TitleDisplayText"; OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = tableCommand; adapter.Fill(dsTitles, "Titles"); // Bind to ComboBox comboBoxTitle.BeginUpdate(); comboBoxTitle.DataSource = dsTitles.Tables["Titles"]; comboBoxTitle.DisplayMember = "TitleDisplayText"; comboBoxTitle.ValueMember = "TitleID"; comboBoxTitle.EndUpdate();
If I create an OracleDataReader and execute the query, adding each item to the ComboBox, it displays, but this takes a considerable amount of time. Any ideas on what I'm doing wrong, or not doing? If this is not the best place to ask, kindly advise a better place. Thanks, Glenn1. Instead of creating a DataSet, create a DataTable.
DataTable dtTitles = new DataTable();
2. Fill the DataTable with the adapteradapter.Fill(dtTitles);
3. Bind the datatablecomboBoxTitle.DataSource = dtTitles;
Hope this helps... Free your mind... -
1. Instead of creating a DataSet, create a DataTable.
DataTable dtTitles = new DataTable();
2. Fill the DataTable with the adapteradapter.Fill(dtTitles);
3. Bind the datatablecomboBoxTitle.DataSource = dtTitles;
Hope this helps... Free your mind...Thanks. Turns out the problem was solved when I removed the comboBox from the form and created a new comboBox with same settings. Worked on all that were causing me grief. --G