jesus4u Posted September 19, 2003 Posted September 19, 2003 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 Quote Alex Polajenko
Administrators PlausiblyDamp Posted September 19, 2003 Administrators Posted September 19, 2003 IIRC DataTable.Select returns an array of rows so you need to declare your variable as an array. Dim drTranscriptSummary() As DataRow 'Changed this line drTranscriptSummary = dtNew.Select("TranscriptsID = 681") Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jesus4u Posted September 19, 2003 Author Posted September 19, 2003 Thank you very much. That did it. How do I read that row of data into my DataGrid? Quote Alex Polajenko
jesus4u Posted September 19, 2003 Author Posted September 19, 2003 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() Quote Alex Polajenko
*Experts* Nerseus Posted September 22, 2003 *Experts* Posted September 22, 2003 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 Quote "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
jesus4u Posted September 22, 2003 Author Posted September 22, 2003 thanks I'll take a look Quote Alex Polajenko
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.