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. update with datagridview

update with datagridview

Scheduled Pinned Locked Moved C#
helpannouncement
5 Posts 4 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.
  • K Offline
    K Offline
    kjosh
    wrote on last edited by
    #1

    Hi, My code like this public string str = "Provider=MSDAORA.1;user id=scott;password=tiger"; OleDbDataAdapter da ; DataSet ds = new DataSet(); OleDbConnection con = new OleDbConnection(str); da= new OleDbDataAdapter("select * from dept", con); da.Fill(ds, "dept"); dataGridView1.DataSource = ds.Tables["dept"]; I want data entered in the datagridview is updated when i click update button. In the button click event i write da.update(ds,"dept"),but it is giving the following exception: "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." In INSERT button click i write like this: DataTable dt=new DataTable(); dt = (DataTable)dataGridView1.DataSource; DataRow dr = dt.NewRow(); dt.Rows.Add(); dataGridView1.DataSource = dt; Please help me. Thanks in advance

    M 1 Reply Last reply
    0
    • K kjosh

      Hi, My code like this public string str = "Provider=MSDAORA.1;user id=scott;password=tiger"; OleDbDataAdapter da ; DataSet ds = new DataSet(); OleDbConnection con = new OleDbConnection(str); da= new OleDbDataAdapter("select * from dept", con); da.Fill(ds, "dept"); dataGridView1.DataSource = ds.Tables["dept"]; I want data entered in the datagridview is updated when i click update button. In the button click event i write da.update(ds,"dept"),but it is giving the following exception: "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." In INSERT button click i write like this: DataTable dt=new DataTable(); dt = (DataTable)dataGridView1.DataSource; DataRow dr = dt.NewRow(); dt.Rows.Add(); dataGridView1.DataSource = dt; Please help me. Thanks in advance

      M Offline
      M Offline
      maryamf
      wrote on last edited by
      #2

      if you want update your data in datagridview in data base you must first define sqlcommandbuilder before your update command: SqlCommandBuilder sc=new SqlCommandBuilder(DataAdaptorname);

      K 1 Reply Last reply
      0
      • M maryamf

        if you want update your data in datagridview in data base you must first define sqlcommandbuilder before your update command: SqlCommandBuilder sc=new SqlCommandBuilder(DataAdaptorname);

        K Offline
        K Offline
        kjosh
        wrote on last edited by
        #3

        I tried in this way also decimal dn=Convert.ToDecimal(textBox2.Text); string d=textBox3.Text; string l=textBox4.Text; string i="insert into dept values(dn,d,l)"; da.InsertCommand=new OleDbCommand(i,con); da.Update(ds, "dept"); It is not giving any error,But updations are not taking place against oracle database. Please help me.

        S M 2 Replies Last reply
        0
        • K kjosh

          I tried in this way also decimal dn=Convert.ToDecimal(textBox2.Text); string d=textBox3.Text; string l=textBox4.Text; string i="insert into dept values(dn,d,l)"; da.InsertCommand=new OleDbCommand(i,con); da.Update(ds, "dept"); It is not giving any error,But updations are not taking place against oracle database. Please help me.

          S Offline
          S Offline
          Sean89
          wrote on last edited by
          #4

          maryamf told you the problem.


          1 Reply Last reply
          0
          • K kjosh

            I tried in this way also decimal dn=Convert.ToDecimal(textBox2.Text); string d=textBox3.Text; string l=textBox4.Text; string i="insert into dept values(dn,d,l)"; da.InsertCommand=new OleDbCommand(i,con); da.Update(ds, "dept"); It is not giving any error,But updations are not taking place against oracle database. Please help me.

            M Offline
            M Offline
            Mairaaj Khan
            wrote on last edited by
            #5

            Hi, in Oracle server, after insert/update execute COMMIT statement for permenent changes in the database. regards, uroojknan -- modified at 2:40 Saturday 27th May, 2006

            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