-
DataSet Question
Once I have filled a dataset is there a set of properties or in-line functions that will allow me to pull the data out of said dataset without having to populate a datagrid?
Code example:
Code:
Connection.Open()
accCommand.CommandText = "SELECT CustID FROM Rental WHERE DvdID = " & DvdID
accCommand.Connection = Connection
dvdDataAdapter.SelectCommand = accCommand
accCommand.ExecuteNonQuery()
dvdDataAdapter.Fill(dvdDataSet, "CustID")
Connection.Close()
I know the information returned from the query is a single value located at (0, 0) I just can't get to it so I can assign the value to the variable. I wouldn't be doing this if I could nail down the syntax for a nested query in Access 2007. Any suggestions?
Thanks guys.
-
Re: DataSet Question
There are various ways you can get specific data out of a DataSet but if all you're getting from the database is a single value then you shouldn't be putting it in a DataSet in the first place. Follow the CodeBank link in my signature and check out my thread on Retrieving and Saving Data. Take a look at the type of code that's appropriate for each scenario and notice that for your scenario you should be call ExecuteScalar.
-
Re: DataSet Question
ExecuteScalar looks to be exactly what I need. And... I used the dataset because that is actually what I was instructed to use. You have to remember that each time I ask a question on here I'm breaking new ground JM. I whole heartedly appreciate your knowledge as well as your prompt responses.
I'm going to toy with ExecuteScalar, I don't exactly know how to use it and your syntax somewhat confused me.
Thanks again man.
-
Re: DataSet Question
I mean do I need to specify a table in here somewhere?
Code:
Dim totalQuantity As Double = CDbl(command.ExecuteScalar())
-
Re: DataSet Question
No freakin way, I just want to carry you around with me, sometimes you amaze me and yet piss me off so bad. Its not as if I don't research prior to posting here, I usually put a good half hour to hour into a problem before I come here and I don't know whether to bow to you or just be more pissed at the ease in which you solve my trivial issues lol!
Code:
Connection.Open()
accCommand.CommandText = "SELECT CustID FROM Rental WHERE DvdID = " & DvdID
accCommand.Connection = Connection
dvdDataAdapter.SelectCommand = accCommand
accCommand.ExecuteNonQuery()
Dim Customer As Integer = CInt(accCommand.ExecuteScalar)
Connection.Close()
-
Re: DataSet Question
You may bow in a pissed off manner. ;) Everything's easy when you know how.
-
Re: DataSet Question