0
votes

Background: Using C# and SQL Server 2008. Query a database and return results to a DataTable (DT_from_SQL), there is an integer column for the primary key (named SQL_table_pk), a column containing a VARCHAR(50) (named SQL_table_char_col1), a column containing a VARCHAR(50) (named SQL_table_char_col2).

I want to add a column (named run_job1_col) to the DataTable, DT_from_SQL, between the first column, SQL_table_pl, and the second column, SQL_table_char_col1. I may want to add another column (named run_job2_col) after the now fourth column, SQL_table_char_col2. The two columns being added need to be checkboxes - the user will check the boxes of all the jobs he wants to run and then submit (I will then have to read the GridView named run_some_SQL_jobs_GridView).

I would then want to read the rows of the DataTable, DT_from_SQL, that have been checked and submitted into an array (named array_of_row_from_SQL_table_in_DataTable_with_checked_checkbox). The array could be multidimensional and contain one array for each of the 0 or more rows with a checked checkbox.

Then I intend to add 0 or more rows to another DataTable from each of the arrays within the multidimensional array. The DataTable the multidimensional array is being added to as row(s) may or may not have the same columns as the arrays within the multidimensional array. Assuming the 2nd DataTable (named DataTable_already_populated_with_rows_and_added_rows_from_an_array) has all the columns that are in DT_from_SQL, except SQL_table_char_col2, and it does not have the either of the checked_checkbox columns.

I tried dt.Columns.Add(new DataColumn("Check", typeof(System.Web.UI.WebControls.CheckBox))); to add a column with checkboxes to DataTable "dt" but it didn't work.

I have been checking my work with: GridView1.DataSource = dt; GridView1.DataBind();

So I can see what is stored in the DataTable ("dt" in this example) and what columns I have added. Please give me a heads up if something wouldn't properly display to a GridView.

This is an ASP.NET web page (.aspx).

1

1 Answers

0
votes

You don't add CheckBox columns to a DataTable.

You probably want to add columns with a data type of Boolean.