Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to cache a table that I can Query using different criteria.

 

Why do I get the error:

 

Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow'.

 

When I try to compile this code?

 

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       If Cache.Item("AllTranscripts") Is Nothing Then
           Dim ds As New DataSet
           ds = dataAccess.ExecuteDataset(conn.ConnectionString, CommandType.StoredProcedure, "GetAllTranscripts")
           Cache.Add("AllTranscripts", ds.Tables(0), Nothing, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Low, Nothing)
           Dim dtNew As DataTable
           dtNew = Cache.Item("AllTranscripts")
           Dim drTranscriptSummary As DataRow
           drTranscriptSummary = dtNew.Select("TranscriptsID = 681")
           DataGrid1.DataSource = drTranscriptSummary
           DataGrid1.DataBind()
       Else
           DataGrid1.DataSource = Cache.Item("AllTranscripts")
           DataGrid1.DataBind()
       End If

   End Sub

Alex Polajenko
Posted

ok got it to filter and bind BUT how can I bind where the one record fills the Grid in one row? The way it is now it loads all the data into one column.

 

           Dim ds As New DataSet
           ds = dataAccess.ExecuteDataset(conn.ConnectionString, CommandType.StoredProcedure, "GetAllTranscripts")
           Cache.Add("AllTranscripts", ds.Tables(0), Nothing, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Low, Nothing)
           drTranscriptSummary = QueryDataTable("TranscriptsID = 681")
           DataGrid1.DataSource = drTranscriptSummary(0).ItemArray
           DataGrid1.DataBind()

Alex Polajenko
  • *Experts*
Posted

I would use a DataView, as in:

Dim ds As New DataSet
ds = dataAccess.ExecuteDataset(conn.ConnectionString, CommandType.StoredProcedure, "GetAllTranscripts")

' I don't remember the enum for the last param, might not be 
' DataViewRowState... check the definition of the DataView constructor
Dim dv As DataView = New DataView(ds.Tables(0), "TranscriptsID = 681", Nothing, DataViewRowState.CurrentRows)
DataGrid1.DataSource = dv
DataGrid1.DataBind()

 

You can create as many DataViews as you want from one Table. Each can have its own filter and sort. In the above, I passed Nothing for the sort - but you can pass a comma delimited list along with "asc" or "desc" for each column.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...