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. help me how to convert BindingSource to DataTable ???

help me how to convert BindingSource to DataTable ???

Scheduled Pinned Locked Moved C#
helpwpfwcftutorialquestion
3 Posts 3 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.
  • P Offline
    P Offline
    phantanagu
    wrote on last edited by
    #1

    Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);

    It seem to be a solution or an answer.

    _ K 2 Replies Last reply
    0
    • P phantanagu

      Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);

      It seem to be a solution or an answer.

      _ Offline
      _ Offline
      _mubashir
      wrote on last edited by
      #2

      Hi, You need to fill dataset first, Dataset dsFunction = New DataSet(); OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); adap.Fill(dsFunction); temp = dsFunction.Tables[0];


      Mubashir Software Architect Storan Technologies Inc, USA Every job is a self portrait of the person who did it.

      1 Reply Last reply
      0
      • P phantanagu

        Hi, After binding datagridview with dataset, when users modify, add or delete the datagridview rows, I want to use datasource of datagridview to run OleCommandBuilder object. But an error appears "Unable to cast object of type bindingsource to type datatable" I am very confused and have you help me how to convert nimdingsource to datatable..... [Code] OleDbDataAdapter adap = new OleDbDataAdapter("Select * from tblVATTU where VATTU_ID = ''", con.con); temp = new DataTable(); MessageBox.Show(dgvVATTU.DataSource.GetType().ToString()); temp = (DataTable)dgvVATTU.DataSource ; // error is here OleDbCommandBuilder buider = new OleDbCommandBuilder(adap); adap.FillSchema(temp, SchemaType.Source); adap.Fill(temp);

        It seem to be a solution or an answer.

        K Offline
        K Offline
        Keshav V Kamat 0
        wrote on last edited by
        #3

        If the datagrid is empty, then fill it first. And then try to bind the table to the datasource. DataGrid1.Rows.Add(1); DataGrid1.Rows[1].Cells[1].Value = "Some String";

        Keshav Kamat :) India

        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