CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    2

    DataTable and DataGridView

    Hi. I have followed this tutorial and i am now showing data in my DataGridView:

    Code:
    void FillData()
            {
                // 1
                // Open connection
                using (SqlCeConnection c = new SqlCeConnection(
                    Properties.Settings.Default.DataConnectionString))
                {
                    c.Open();
                    // 2
                    // Create new DataAdapter
                    using (SqlCeDataAdapter a = new SqlCeDataAdapter(
                        "SELECT * FROM Animals", c))
                    {
                        // 3
                        // Use DataAdapter to fill DataTable
                        DataTable t = new DataTable();
                        a.Fill(t);
                        // 4
                        // Render data onto the screen
                        dataGridView1.DataSource = t;
                    }
                }
            }
    Now I want to be able to modify the data and write it back to the database. How would i do this ? Create a function called SaveData and:
    - create a connection
    - create a new adapter ( that writes )
    - create the datatable
    - write datatable to new adapter using the connection

    I was wondering if that thought process is correct. I barely have any C# coding experiences alltho this does not seem so hard. Help is appreicated

  2. #2
    Join Date
    Feb 2011
    Posts
    2

    Re: DataTable and DataGridView


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured