Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid DataSet DataTable maddness

Status
Not open for further replies.

intrex

IS-IT--Management
Apr 14, 2002
70
US
Hello,

I have been working on a data problem for a little while now. I am looking for some good direction of where to go from here.

I created a SqlDataAdapter, SqlConnection, and a DataTable. I instantiate my SqlAdapter with a storedprocedure and my SqlConnection. Then I populate the DataTable with the results of the SqlDataAdapters fill method. Finally I bind this DataTable to a DataGrid that I display to users on an ASPX page.

Now my troubles begin.

From here I added two columns (with editable textbox objects in them) to the end of the DataGrid.

<ItemTemplate>
<asp:TextBox runat="server" ID="txtMeas" "50px" /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="Comments"> <ItemTemplate>
<asp:TextBox runat="server" ID="Textbox1" />
</ItemTemplate>

I want to be able to fill a SQL table with results from the DataGrid (including the textbox columns) and several other pieces of data all merged together.

I have not had much luck doing this in a .Net fasion. I know that I could accomplish this by turning all of the data in the datagrid into arrays or collections and then iterating through the arrays and manipulating the data. If I were to go about this method then why am I using all of these high level objects? I feel like I should just go back to creating a sql command and getting resultsets that I turn into arrays.

Any guidance would be greatly appreciated. Some example code of creating custom columns, and rows in DataSets, DataGrids, or DataTables would be very helpfull. I have found it very hard to add columns to any of these object unless I add the columns to the end of them.
 
you can simply add two columns to the datatable you filled with the dataAdapter in order to have your datagrid contain all the columns from the start (and I also believe you can use the InsertAt method of the Columns collection from the datatable to insert your columns at whatever position you need)

as for the rest, in C# you can have a dataadapter fill a datatable in a dataset, then you can autogenerate the update, delete and insert commands using SqlCommandBuilder based on your select command (there are some restrictions though) and then simply call the dataset's Update method for a certain table (the one that needs updating), and all is take care of automatically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top