Persist a dataset

P

Paul Ilacqua

How do I persist a dataset to another procedure in a form IE
'Code

Public ds as Dataset
'Fill and use Dataset in LoadProjects but I want to use this dataset from
another sub in the same form class.


Private Sub LoadProjects()

Using objData As New OLEDBBase

ds = New DataSet

Try

With objData

..SQL = "Select PartNumber,Sum([OH INV]) From Inventory Group By PartNumber"

..InitializeCommand()

..OpenConnection()

'DS is Filled Here

..FillDataSet(ds, "Builds")

End With

Dim iCounter As Integer = 0

Dim row As DataRow

ListBox1.Items.Clear()

For Each row In ds.Tables(0).Rows

ListBox1.Items.Add(row(0))

Next row



objData.DataReader.Close()

ds.Clear()

Catch ExceptionErr As Exception

MessageBox.Show(ExceptionErr.Message, "Error")

End Try

End Using

End Sub
 
M

Miha Markic [MVP C#]

Hi Paul,

Don't call ds.Clear and pass ds to another method?
BTW, why do you need: objData.DataReader.Close()?
 
P

Paul Ilacqua

I was experimenting with a Datareader VS as dataset. I'm filling a Listbox
with part numbers with a data reader, then after clicking on a part number,
then I was getting an Inventory (single number) for that part number. Then I
thought I'll set up a dataset /datatable with the part number and the
inventory... fill the list box with the part number, then lookup the
inventory instead of continually hitting the db. I'm learning VB .NET & and
want to learn how to do things correctly.

How do I pass ds to another method?

Thank you for your help.

Miha Markic said:
Hi Paul,

Don't call ds.Clear and pass ds to another method?
BTW, why do you need: objData.DataReader.Close()?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Paul Ilacqua said:
How do I persist a dataset to another procedure in a form IE
'Code

Public ds as Dataset
'Fill and use Dataset in LoadProjects but I want to use this dataset from
another sub in the same form class.


Private Sub LoadProjects()

Using objData As New OLEDBBase

ds = New DataSet

Try

With objData

.SQL = "Select PartNumber,Sum([OH INV]) From Inventory Group By
PartNumber"

.InitializeCommand()

.OpenConnection()

'DS is Filled Here

.FillDataSet(ds, "Builds")

End With

Dim iCounter As Integer = 0

Dim row As DataRow

ListBox1.Items.Clear()

For Each row In ds.Tables(0).Rows

ListBox1.Items.Add(row(0))

Next row



objData.DataReader.Close()

ds.Clear()

Catch ExceptionErr As Exception

MessageBox.Show(ExceptionErr.Message, "Error")

End Try

End Using

End Sub
 
M

Miha Markic [MVP C#]

As a parameter of type DataSet to the method

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Paul Ilacqua said:
I was experimenting with a Datareader VS as dataset. I'm filling a Listbox
with part numbers with a data reader, then after clicking on a part number,
then I was getting an Inventory (single number) for that part number. Then
I thought I'll set up a dataset /datatable with the part number and the
inventory... fill the list box with the part number, then lookup the
inventory instead of continually hitting the db. I'm learning VB .NET & and
want to learn how to do things correctly.

How do I pass ds to another method?

Thank you for your help.

Miha Markic said:
Hi Paul,

Don't call ds.Clear and pass ds to another method?
BTW, why do you need: objData.DataReader.Close()?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Paul Ilacqua said:
How do I persist a dataset to another procedure in a form IE
'Code

Public ds as Dataset
'Fill and use Dataset in LoadProjects but I want to use this dataset
from another sub in the same form class.


Private Sub LoadProjects()

Using objData As New OLEDBBase

ds = New DataSet

Try

With objData

.SQL = "Select PartNumber,Sum([OH INV]) From Inventory Group By
PartNumber"

.InitializeCommand()

.OpenConnection()

'DS is Filled Here

.FillDataSet(ds, "Builds")

End With

Dim iCounter As Integer = 0

Dim row As DataRow

ListBox1.Items.Clear()

For Each row In ds.Tables(0).Rows

ListBox1.Items.Add(row(0))

Next row



objData.DataReader.Close()

ds.Clear()

Catch ExceptionErr As Exception

MessageBox.Show(ExceptionErr.Message, "Error")

End Try

End Using

End Sub
 

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

Top