Question Display data from a dataTable or SqlDataAdapter

asest

Member
Joined
Aug 25, 2010
Messages
7
Location
Kent, UK
Programming Experience
1-3
Probably various ways of doing this and reasons why some ways are better than others.

I am probably not going about things the best way but owing to my limited experience, it is what it is and any help would be much appreciated.

I have pulled data from a sql database, put into a sqldataadapter, then stored in a session.

Now I wish to retrieve the data from the session (which was stored as a sqldataadpater, not my initial intention), put to a datagrid via a datatable and having retrived the sesison vars through a sqldataadapter.

This all works fine (below).
As my next part of the process I need to compare a piece of the data that is displayed in that datagrid (which had originally been kept in the session as a sqldataadapter).

My first port of call was to simply access and display the relevant data to keep things simple.
This is where I have had difficulties.

I have tried several alternatives and have been unable to find the solution.

A couple of my many attempts (using data from the datagrid, sqldataadapter and the datatable)...
myAspLabel.Text = dtAA.Columns.Item(0).ColumnName("myColName").ToString()
myAspLabel.Text = Convert.ToString(dtAA.Rows("myColName").Item(0))

Sub bindAA()

Dim dtAA As New DataTable()
Dim dtadapter As New SqlDataAdapter()

dtadapter = Session("dataset")

dtadapter.Fill(dtAA)
myDataGrid.DataSource = dtAA
myDataGrid.DataBind()

End Sub

<asp:DataGrid ID="myDataGrid" runat="server" Width="100%" AutoGenerateColumns="false">
<columns>
<asp:BoundColumn Datafield="CU_AADate" DataFormatString="{0:dd-MM-yyyy}" ReadOnly="true" />
<asp:BoundColumn Datafield="CU_AAValue" DataFormatString="{0:£0.00}" ReadOnly="true" />
<asp:BoundColumn Datafield="CU_AAAVCConts" DataFormatString="{0:£0.00}" ReadOnly="true" />
<asp:BoundColumn Datafield="myColName" DataFormatString="{0:£0.00}" ReadOnly="true" />

</columns>
</asp:DataGrid>
<asp:Label runat="server" ID="myAspLabel" />


I am sure the answer to this is simple but just need pointing in the right direction.

Many thanks
 
I think that you misunderstand what a data adapter is. No data is stored in a data adapter. It's purpose is to group up to four commands that, together, will populate one or more DataTables with data retrieved from a data source and also save changes from those DataTables back to a data source. Usually it is only one DataTable and usually the source and target data sources are the same database.

So, in your case, you would want to use a data adapter to populate a DataTable and store that in the session. Later on, you might construct another data adapter in the same way and use it to save the changes from that DataTable back to your database.

Also, I would recommend that you not name your session variable "dataset" if it's not a DataSet. Use a name that is primarily descriptive of the object's purpose and, secondarily, its type.
 

Latest posts

Back
Top