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. filling a dataGridView, editing and overwriting [modified]

filling a dataGridView, editing and overwriting [modified]

Scheduled Pinned Locked Moved C#
questiondatabasesecurityhelpannouncement
9 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.
  • E Offline
    E Offline
    Emmet_Brown
    wrote on last edited by
    #1

    Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:

    string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
    SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
    SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
    DataSet ds = new DataSet();
    da.Fill(ds);
    dbGridView.DataSource = ds.Tables[0];

    it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:

    private void saveButton_Click(object sender, EventArgs e)
    {
    string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
    SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
    SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
    DataSet ds = new DataSet();
    da.Fill(ds);
    da.Update(ds);
    this.Close();

        }
    

    bu "da.Update(ds)" does not update my table in the database where is my mistake?

    modified on Tuesday, December 1, 2009 1:06 AM

    D S 3 Replies Last reply
    0
    • E Emmet_Brown

      Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:

      string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
      SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
      SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
      DataSet ds = new DataSet();
      da.Fill(ds);
      dbGridView.DataSource = ds.Tables[0];

      it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:

      private void saveButton_Click(object sender, EventArgs e)
      {
      string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
      SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
      SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
      DataSet ds = new DataSet();
      da.Fill(ds);
      da.Update(ds);
      this.Close();

          }
      

      bu "da.Update(ds)" does not update my table in the database where is my mistake?

      modified on Tuesday, December 1, 2009 1:06 AM

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      This[^] might help.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      E 1 Reply Last reply
      0
      • D dan sh

        This[^] might help.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        E Offline
        E Offline
        Emmet_Brown
        wrote on last edited by
        #3

        unfortunately no it only tells how to update the table in a single action. I want to save the whole table at once :/

        D 1 Reply Last reply
        0
        • E Emmet_Brown

          Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:

          string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
          SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
          SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
          DataSet ds = new DataSet();
          da.Fill(ds);
          dbGridView.DataSource = ds.Tables[0];

          it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:

          private void saveButton_Click(object sender, EventArgs e)
          {
          string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
          SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
          SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
          DataSet ds = new DataSet();
          da.Fill(ds);
          da.Update(ds);
          this.Close();

              }
          

          bu "da.Update(ds)" does not update my table in the database where is my mistake?

          modified on Tuesday, December 1, 2009 1:06 AM

          S Offline
          S Offline
          souidi abderrahman
          wrote on last edited by
          #4

          if you wanna see the mistake try to put toggle breakpoint in you methods and debogue step by step F10. it's easy to debugue :) :) :zzz:

          E 1 Reply Last reply
          0
          • S souidi abderrahman

            if you wanna see the mistake try to put toggle breakpoint in you methods and debogue step by step F10. it's easy to debugue :) :) :zzz:

            E Offline
            E Offline
            Emmet_Brown
            wrote on last edited by
            #5

            of course I did that :D compiler just acts as if it ignores the update method, It tells me as if "executes" the update, but I cannot see any change on DB

            1 Reply Last reply
            0
            • E Emmet_Brown

              unfortunately no it only tells how to update the table in a single action. I want to save the whole table at once :/

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #6

              In the button click, you are again fetching the data from the database. Here, you should be using the dataset you have modified. Then, you have not mentioned any update command for your adapter so it will not know what and where to update. You should: 1. Use the same dataset that you have used to fetch the data 2. Use same adapter as earlier and set its update command. Also, read the description of the SQLDataAdapter.Update method from MSDN. It should be having some sample code that will help you understand.

              50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

              E 1 Reply Last reply
              0
              • D dan sh

                In the button click, you are again fetching the data from the database. Here, you should be using the dataset you have modified. Then, you have not mentioned any update command for your adapter so it will not know what and where to update. You should: 1. Use the same dataset that you have used to fetch the data 2. Use same adapter as earlier and set its update command. Also, read the description of the SQLDataAdapter.Update method from MSDN. It should be having some sample code that will help you understand.

                50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

                E Offline
                E Offline
                Emmet_Brown
                wrote on last edited by
                #7

                oh thank you, I'll have a look =)

                1 Reply Last reply
                0
                • E Emmet_Brown

                  Hello everyone I've once asked this question but I thought that I couldn't make it clear. I have a table and I want to view it on my dataGridView. I need to fill this dataGridView by codes, not with the interface. I also allowed the user to edit this dataGridView in the runtime. User can change the values of cells, and also add rows to the table. My two questions are: how can I fill this dataGridView by hardcoding and how can I overwrite the loaded table with the edited table by the user? please please please help and be clear with me in this. I'm pretty rookie and this is the only thing left in my project to finish :( EDIT! Somehow I managed to fill the table, now, only saving left. Please. Anyone? EDIT2 well, I did sth :) I'm filling the table like this:

                  string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
                  SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
                  SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
                  DataSet ds = new DataSet();
                  da.Fill(ds);
                  dbGridView.DataSource = ds.Tables[0];

                  it works, and from the same source, someone says that "you can use 'da.Update(ds);' for updating your table" I want to update the table on some SAVE button, so I wrote this:

                  private void saveButton_Click(object sender, EventArgs e)
                  {
                  string strCon = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Veritabani.sdf; Persist Security Info=False";
                  SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon);
                  SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);
                  DataSet ds = new DataSet();
                  da.Fill(ds);
                  da.Update(ds);
                  this.Close();

                      }
                  

                  bu "da.Update(ds)" does not update my table in the database where is my mistake?

                  modified on Tuesday, December 1, 2009 1:06 AM

                  S Offline
                  S Offline
                  souidi abderrahman
                  wrote on last edited by
                  #8

                  what is the SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);????? it's SqlDataAdapter not SqlCeDataAdapter!!! and SqlCommandBuilder not SqlCeCommandBuilder !!!:confused:

                  E 1 Reply Last reply
                  0
                  • S souidi abderrahman

                    what is the SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Kasa", strCon); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);????? it's SqlDataAdapter not SqlCeDataAdapter!!! and SqlCommandBuilder not SqlCeCommandBuilder !!!:confused:

                    E Offline
                    E Offline
                    Emmet_Brown
                    wrote on last edited by
                    #9

                    they are SQL Compact Edition commands :D

                    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