Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Oracle Help Needed - ComboBox data binding

Oracle Help Needed - ComboBox data binding

Scheduled Pinned Locked Moved Database
databasecsharpsql-serveroraclewpf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • G Glenn E Lanier II

      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

      G Offline
      G Offline
      Guillermo Rivero
      wrote on last edited by
      #2

      1. Instead of creating a DataSet, create a DataTable. DataTable dtTitles = new DataTable(); 2. Fill the DataTable with the adapter adapter.Fill(dtTitles); 3. Bind the datatable comboBoxTitle.DataSource = dtTitles; Hope this helps... Free your mind...

      G 1 Reply Last reply
      0
      • G Guillermo Rivero

        1. Instead of creating a DataSet, create a DataTable. DataTable dtTitles = new DataTable(); 2. Fill the DataTable with the adapter adapter.Fill(dtTitles); 3. Bind the datatable comboBoxTitle.DataSource = dtTitles; Hope this helps... Free your mind...

        G Offline
        G Offline
        Glenn E Lanier II
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups