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. Editable data grid view?

Editable data grid view?

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

    Hello everyone I want a fully editable, DB interacted data grid view. By some mystake, the system has multiple DB's and I cannot use the interface. I have to enter the code to call a table from a specific database, I don't ask how can I fix this, we got along together well until now :) I made this data grid view editable, that user can add rows and edit info on the table. My questions are -How can I call a table from database to view in this grid view -How can I save the table's final state? (this is a single usered non-online system so performance is not issue, I can appreciate a solution that drops the previous table and creates a new one with the edited data grid view) Thank you

    J 1 Reply Last reply
    0
    • E Emmet_Brown

      Hello everyone I want a fully editable, DB interacted data grid view. By some mystake, the system has multiple DB's and I cannot use the interface. I have to enter the code to call a table from a specific database, I don't ask how can I fix this, we got along together well until now :) I made this data grid view editable, that user can add rows and edit info on the table. My questions are -How can I call a table from database to view in this grid view -How can I save the table's final state? (this is a single usered non-online system so performance is not issue, I can appreciate a solution that drops the previous table and creates a new one with the edited data grid view) Thank you

      J Offline
      J Offline
      JollyMansArt
      wrote on last edited by
      #2

      -How can I call a table from database to view in this grid view

         SqlDataAdapter SQL\_Adapter;
              DataTable dtReport1 = new DataTable();
              string SQL\_Command = "SQL STATEMENT GOES HERE"
              //if (cklbxColumns.Items.Count != 0)
              //{
                  SQL\_Command += "'" + strExecutive + "', '" + strToolClass + "'";
              //}
      
              try
              {
                  using (SQL\_Conn = new SqlConnection(WhatIsTheSQLConnectionString))
                  {
                      if (SQL\_Conn.State != ConnectionState.Open)
                      {
                          SQL\_Conn.Open();
                      }
                      else
                      {
                          SQL\_Conn.Close();
                          SQL\_Conn.Open();
                      }
      
                      //using (SQL\_Adapter = new SqlDataAdapter("SQL STATEMENT GOES HERE", SQL\_Conn))
                      using (SQL\_Adapter = new SqlDataAdapter(SQL\_Command, SQL\_Conn))
                      {
                          // Use DataAdapter to fill DataTable
      
                          SQL\_Adapter.Fill(dtReport1);
                          // 4
                          // Render data onto the screen
                          // dgvReport = DataGridViewer
                          dgvReport.DataSource = dtReport1;
                          //dgvReport.DataMember = "dtToolStatusboardReport";
                          dgvReport.Refresh();
                          gbToolStatusBoard.Refresh();
                          //ActiveForm.Refresh();
                      }
                      SQL\_Adapter.Dispose();
                  }
                  SQL\_Conn.Close();
              }
              catch
              { return; }
      

      -How can I save the table's final state? (this is a single usered non-online system so performance is not issue, I can appreciate a solution that drops the previous table and creates a new one with the edited data grid view) For this method you would simply export the datatable directly back to the main table after flushing out the data in the origional table.

      E 1 Reply Last reply
      0
      • J JollyMansArt

        -How can I call a table from database to view in this grid view

           SqlDataAdapter SQL\_Adapter;
                DataTable dtReport1 = new DataTable();
                string SQL\_Command = "SQL STATEMENT GOES HERE"
                //if (cklbxColumns.Items.Count != 0)
                //{
                    SQL\_Command += "'" + strExecutive + "', '" + strToolClass + "'";
                //}
        
                try
                {
                    using (SQL\_Conn = new SqlConnection(WhatIsTheSQLConnectionString))
                    {
                        if (SQL\_Conn.State != ConnectionState.Open)
                        {
                            SQL\_Conn.Open();
                        }
                        else
                        {
                            SQL\_Conn.Close();
                            SQL\_Conn.Open();
                        }
        
                        //using (SQL\_Adapter = new SqlDataAdapter("SQL STATEMENT GOES HERE", SQL\_Conn))
                        using (SQL\_Adapter = new SqlDataAdapter(SQL\_Command, SQL\_Conn))
                        {
                            // Use DataAdapter to fill DataTable
        
                            SQL\_Adapter.Fill(dtReport1);
                            // 4
                            // Render data onto the screen
                            // dgvReport = DataGridViewer
                            dgvReport.DataSource = dtReport1;
                            //dgvReport.DataMember = "dtToolStatusboardReport";
                            dgvReport.Refresh();
                            gbToolStatusBoard.Refresh();
                            //ActiveForm.Refresh();
                        }
                        SQL\_Adapter.Dispose();
                    }
                    SQL\_Conn.Close();
                }
                catch
                { return; }
        

        -How can I save the table's final state? (this is a single usered non-online system so performance is not issue, I can appreciate a solution that drops the previous table and creates a new one with the edited data grid view) For this method you would simply export the datatable directly back to the main table after flushing out the data in the origional table.

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

        oh thank you, I'll give it a try

        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