querying data from a dataset?

M

MDB

I'd normally Google for a question like this, and hope to snag a few
examples along with the answer, but this time I can't see to get the
keywords specific enough.

Or I'd ask coworkers, but they're just as new to ASP.NET as I am.

Is it possible to have a dataset filled with all the records in an SQL table
(on the small side, maybe three hundred records total), and then query that
table for subsets of data, e.q. a simple WHERE clause, to deal with all the
changes the data must go through on screen depending on the state and value
of several dropdown controls? It seems to me that that would be a little
more efficient than having about a dozen stored procedures and re-querying
the SQL table on every changed event. If the answer is yes, how do I go
about pulling a subset from a dataset in memory?

If the answer is no, or if the answer is that I'm better off with the stored
procedures, I'm okay with that. Just checking to see if there's Another Way.
Thanks!

MD Bloemker
(e-mail address removed)
 
K

Ken Cox [Microsoft MVP]

If I understand you correctly, you want to get one dataset and then filter
it for different uses?

If so, you can create a DataView and apply SQL-like syntax to it:

Private Sub MakeDataView()
Dim dv As DataView
dv = New DataView
With dv
.Table = DataSet1.Tables("Suppliers")
.AllowDelete = True
.AllowEdit = True
.AllowNew = True
.RowFilter = "City = 'Berlin'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
.Sort = "CompanyName DESC"
End With

' Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "CompanyName")
End Sub



http://msdn.microsoft.com/library/d...rlrfsystemdatadataviewclassrowfiltertopic.asp
 
W

William F. Robertson, Jr.

Your best bet is to use the Select method for the DataTable.

SqlDataAdapter.Fill( table );

DataRow [] rows = table.Select( "journalid = " + ddlJournalID.SelectedValue
+ " AND "Type = " + ddlType.SelectedValue );

You can then bind rows to what ever you want.

Or if you need more control, you can look into building a DataView using the
DataTable as backing.

HTH,

bill
 
E

Eliyahu Goldin

Yes, you can query a datatable in a dataset with method Select. Whoever, I
would still recommend querying the database. That is what it is there for.
And you would end up with less code.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top