johndeerb
asked on
Select specific field from dataset
I'm a rookie at asp.net, so I apologize if this question is stupid.
I have a page that needs information from a SQL DB, so I have been making multiple connections to the DB during page load and event handlers on the page. As I'm adding functionality to the page, I want to stop making so many connections to the database. I decided to connect to the DB in the page load event and fill a couple of datasets or datatables with the data that I need to display on the page and then pull what is needed from those datasets or datatables. This is where I'm getting stumped. I currently have one dataset and one datatable that are getting filled at page load. I know this works because I can throw a gridview on the page and bind it to the dataset or datatable and it displays all the data that I queried from the DB. Now the problem...
I need to be able to query specific data from the dataset like I would from SQL to display when certain events fire, but I haven't figured out how yet. I read that I could use the datatable.select method to grab an entire row from a table, but I need to query for one field based on criteria. Here is a partial layout of the datatable:
_date _name _dept
08/01/2008 John I.T.
08/01/2008 Joel Maintenance
08/01/2008 Bill Biomed
08/02/2008 Brad I.T.
08/02/2008 Wes Maintenance
08/02/2008 Ken Biomed
and so on... what I need is to be able to query something like
Select _name from mydatatable where date = '08/01/2008' AND _dept = 'Biomed'
so that I can display that name on a calendar or other form controls..
Again, I apologize for the newbie question. Can anyone get me started in the right direction?
Thanks in advance for you help!
I have a page that needs information from a SQL DB, so I have been making multiple connections to the DB during page load and event handlers on the page. As I'm adding functionality to the page, I want to stop making so many connections to the database. I decided to connect to the DB in the page load event and fill a couple of datasets or datatables with the data that I need to display on the page and then pull what is needed from those datasets or datatables. This is where I'm getting stumped. I currently have one dataset and one datatable that are getting filled at page load. I know this works because I can throw a gridview on the page and bind it to the dataset or datatable and it displays all the data that I queried from the DB. Now the problem...
I need to be able to query specific data from the dataset like I would from SQL to display when certain events fire, but I haven't figured out how yet. I read that I could use the datatable.select method to grab an entire row from a table, but I need to query for one field based on criteria. Here is a partial layout of the datatable:
_date _name _dept
08/01/2008 John I.T.
08/01/2008 Joel Maintenance
08/01/2008 Bill Biomed
08/02/2008 Brad I.T.
08/02/2008 Wes Maintenance
08/02/2008 Ken Biomed
and so on... what I need is to be able to query something like
Select _name from mydatatable where date = '08/01/2008' AND _dept = 'Biomed'
so that I can display that name on a calendar or other form controls..
Again, I apologize for the newbie question. Can anyone get me started in the right direction?
Thanks in advance for you help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks cmhunty, I think that will do it. Here's what I wound up with:
Dim dv As New DataView(mydt)
dv.RowFilter = "_date = '08/01/2008' AND _dept = 'Biomed'"
Dim drv As DataRowView
For Each drv In dv
Me.Label3.Text = "Name is " & drv.Row("_name")
Next
Of course, I'll need to work on some error catching and such now, but his has the nuts and bolts I was looking for. Thanks for tolerating a newbie question.
Dim dv As New DataView(mydt)
dv.RowFilter = "_date = '08/01/2008' AND _dept = 'Biomed'"
Dim drv As DataRowView
For Each drv In dv
Me.Label3.Text = "Name is " & drv.Row("_name")
Next
Of course, I'll need to work on some error catching and such now, but his has the nuts and bolts I was looking for. Thanks for tolerating a newbie question.
ASKER
Pra444 -
Thanks for your post. It might have been a solution, but the link gave example code in c#. I'm using VB.net (probably should have included that bit of info in the question, huh?) I'm sorry for not being more clear.
Thanks for your post. It might have been a solution, but the link gave example code in c#. I'm using VB.net (probably should have included that bit of info in the question, huh?) I'm sorry for not being more clear.
ASKER
Thanks again!
http://www.codeproject.com/KB/cs/DatasetFilter.aspx