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. General Programming
  3. C#
  4. OleDbDataAdapter and more tables

OleDbDataAdapter and more tables

Scheduled Pinned Locked Moved C#
helpquestiondatabaseannouncement
2 Posts 2 Posters 3 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.
  • M Offline
    M Offline
    mkomasi
    wrote on last edited by
    #1

    Hi, I want to use DataSet and OleDbDataAdapter for manipulating some tables of a database. I know that when I want to do it for a table I can use below code: { DataSet custDS = new DataSet(); OleDbConnection myConn = new OleDbConnection(myConnection); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(); myDataAdapter.SelectCommand = new OleDbCommand(); myDataAdapter.SelectCommand.Connection = myConnection; OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter); myDataAdapter.SelectCommand.CommandText = "Select * from Customers"; myDataAdapter.Fill(custDS, "Customers"); //code to modify data in dataset here //Without the OleDbCommandBuilder this line would fail myDataAdapter.Update(custDS, "Customers"); } but when I want to use more tables I have, some problems: { DataSet custDS = new DataSet(); OleDbConnection myConn = new OleDbConnection(myConnection); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(); myDataAdapter.SelectCommand = new OleDbCommand(); myDataAdapter.SelectCommand.Connection = myConnection; OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter); myDataAdapter.SelectCommand.CommandText = "Select * from Customers"; myDataAdapter.Fill(custDS, "Customers"); myDataAdapter.SelectCommand.CommandText = "Select * from Orders"; myDataAdapter.Fill(custDS, "Orders"); myDataAdapter.SelectCommand.CommandText = "Select * from Products"; myDataAdapter.Fill(custDS, "Products"); //code to modify data in dataset here //Without the OleDbCommandBuilder this line would fail myDataAdapter.Update(custDS, "Customers"); myDataAdapter.Update(custDS, "Orders"); myDataAdapter.Update(custDS, "Products"); } Because the myDataAdapter only gives one SelectCommand and CommandBuilder generates some commannds for one of tables. So myDataAdapter.Update method works for one of tables. Can anyone help me please? How can I use OleDbDataAdpter, DataSet and CommandBuilder to solve my problem?

    L 1 Reply Last reply
    0
    • M mkomasi

      Hi, I want to use DataSet and OleDbDataAdapter for manipulating some tables of a database. I know that when I want to do it for a table I can use below code: { DataSet custDS = new DataSet(); OleDbConnection myConn = new OleDbConnection(myConnection); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(); myDataAdapter.SelectCommand = new OleDbCommand(); myDataAdapter.SelectCommand.Connection = myConnection; OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter); myDataAdapter.SelectCommand.CommandText = "Select * from Customers"; myDataAdapter.Fill(custDS, "Customers"); //code to modify data in dataset here //Without the OleDbCommandBuilder this line would fail myDataAdapter.Update(custDS, "Customers"); } but when I want to use more tables I have, some problems: { DataSet custDS = new DataSet(); OleDbConnection myConn = new OleDbConnection(myConnection); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(); myDataAdapter.SelectCommand = new OleDbCommand(); myDataAdapter.SelectCommand.Connection = myConnection; OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter); myDataAdapter.SelectCommand.CommandText = "Select * from Customers"; myDataAdapter.Fill(custDS, "Customers"); myDataAdapter.SelectCommand.CommandText = "Select * from Orders"; myDataAdapter.Fill(custDS, "Orders"); myDataAdapter.SelectCommand.CommandText = "Select * from Products"; myDataAdapter.Fill(custDS, "Products"); //code to modify data in dataset here //Without the OleDbCommandBuilder this line would fail myDataAdapter.Update(custDS, "Customers"); myDataAdapter.Update(custDS, "Orders"); myDataAdapter.Update(custDS, "Products"); } Because the myDataAdapter only gives one SelectCommand and CommandBuilder generates some commannds for one of tables. So myDataAdapter.Update method works for one of tables. Can anyone help me please? How can I use OleDbDataAdpter, DataSet and CommandBuilder to solve my problem?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      mkomasi wrote: OleDbCommandBuilder custCB = new OleDbCommandBuilder(myDataAdapter); myDataAdapter.SelectCommand.CommandText = "Select * from Customers"; myDataAdapter.Fill(custDS, "Customers"); myDataAdapter.SelectCommand.CommandText = "Select * from Orders"; myDataAdapter.Fill(custDS, "Orders"); myDataAdapter.SelectCommand.CommandText = "Select * from Products"; myDataAdapter.Fill(custDS, "Products"); You need to run the COmmandBuilder each time after you change your "select" statement. But then u have a problem with the Update (you will have to do the whole thing again). I recommend setting up a dataadapter for each table. MyDUMeter: a .NET DUMeter clone

      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