|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Persist a dataset'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 Hi Paul,
Don't call ds.Clear and pass ds to another method? BTW, why do you need: objData.DataReader.Close()? -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Paul Ilacqua" <pilac***@twcny.rr.com> wrote in message news:ekDivgANGHA.1028@TK2MSFTNGP11.phx.gbl... > 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 > > 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. Show quote "Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:OCYpvFGNGHA.2920@TK2MSFTNGP10.phx.gbl... > 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" <pilac***@twcny.rr.com> wrote in message > news:ekDivgANGHA.1028@TK2MSFTNGP11.phx.gbl... >> 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 >> >> > > As a parameter of type DataSet to the method
-- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Paul Ilacqua" <pilac***@twcny.rr.com> wrote in message news:usi65JMNGHA.536@TK2MSFTNGP09.phx.gbl... >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 [MVP C#]" <miha at rthand com> wrote in message > news:OCYpvFGNGHA.2920@TK2MSFTNGP10.phx.gbl... >> 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" <pilac***@twcny.rr.com> wrote in message >> news:ekDivgANGHA.1028@TK2MSFTNGP11.phx.gbl... >>> 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 >>> >>> >> >> > > |
|||||||||||||||||||||||