using dataset to store data

elloco999

Well-known member
Joined
Dec 21, 2004
Messages
49
Programming Experience
5-10
Hi,

I have written a small program that gets some data from a SQL Server and uses this data to create and send an email for each record.

I use a datareader to get the data from the DB (using a stored procedure). Then reading the datareader line by line I put the data in an array. After that, I close the datareader and create and send the emails. For each email a record is added to another table in the DB (again using a stored procedure).

I would prever to use a dataset to store the data, instead of the array. I tried this when I wrote the program, but couldn't get it to work. Now I want to change the program to use a dataset (or something else if someone knows anything that would do the trick :).

If anyone can help me gettting started... The MSDN isn't very clear on this subject. Last time I didn't even get the dataset properly initialized. Any help would be welcome.

Greetz,
El Loco
 
Ok, I've gotten all the data in the dataset. But how can I read it from the ataset, one row at a time?

My dataset is filled with one table. The table has 6 columns: id, to, cc, bcc, subject and body. How do I read one line (record) from the dataset, into 6 variables so I can use these variables to make and send the email?

El Loco
 
Hi,
U can use loop as .........

for intRows = 0 to dataset.rows.Count-1
For intCol =0 to dataset.Columns.Count-1
'Here u write ur own code..........................e.g
ID = dataSet.rows(intRows).item(intCol)

OR

ID = dataSet.rows(intRows).item("ID")

so on.................
Next

Next


I hope this will help u..............................

Reagrds,
Ritesh
 
There's a few errors in Ritesh's code above.

for intRows = 0 to dataset.rows.Count-1
should be
For intRows = 0 to dataSet.Tables(0).Rows.Count - 1
or
For intRows = 0 to dataSet.Tables("TableName").Rows.Count - 1

also
For intCol =0 to dataset.Columns.Count-1
should be
For intCol = 0 to dataSet.Tables(0).Columns.Count -1


I beleive a dataTable instead of a dataSet should suffice for your application. A dataAdapter can be used to fill a dataTable. A dataSet is used for containing multiple dataTables and sometimes relations between those dataTables.
 
Hi,

Thanks for the info. I got the following code from another forum:

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] DataSetRow [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataRow
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] intRequestId [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
[/color][/size]
[size=2][color=#0000ff]For[/color][/size][size=2][color=#0000ff]Each[/color][/size][size=2] DataSetRow [/size][size=2][color=#0000ff]In[/color][/size][size=2] MyDataSet.Tables(0).Rows[/size]
[size=2]intRequestId = DataSetRow.ItemArray.GetValue(0).ToString()[/size]
 
[size=2][color=#008000]'Insert code here
[/color][/size][size=2][size=2][color=#0000ff]Next
[/color][/size][/size]


This works perfecly (as long as you know what is in the columns...)

Greetz,
El Loco


 
Back
Top