[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dataset fill through a class

Posted on 2004-11-25
6
Medium Priority
?
248 Views
Last Modified: 2010-04-23
I have a program I wrote a little while back and in it I fill various datasets using the OleDBDataAdapter.  The code looks something like this:
Dim ds as New Dataset
Dim adapter as New OleDBDataAdapter("SELECT * From DB", connstring)
adapter.fill(ds, "DB")

I would like to create a class that could replace the OleDBDataAdapter with my own dataadapter such as JWDataAdapter that has the ability to fill a dataset. So I could simply do a find and replace and replace everything that has OleDB with JW.  However I don't know how I could fill the dataset.  So the code would look something like this:

Dim ds as New Dataset
Dim adapter as New JWDataAdapter("SELECT * From DB", connstring)
adapter.fill(ds, "DB")


Any ideas?
0
Comment
Question by:johnywhite
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 12676904
Create a class called JWDataAdapter. Implement a constructor that overloads the New. Then add a Fill method. Inside this method, use the OLEDb objects to perform the fill.

What are you trying to acheive?
0
 

Author Comment

by:johnywhite
ID: 12676982
I guess what I am don't know is how to fill the dataset which is in the form calling the class.  I don't know if I am explaining myself very well.  What i am trying to do is turn an invoice program that I created into a web-enabled program.  I want the database to get the data off of my web-site through a web-service rather than have it stored on a local database.  I want to do this with minimal effort, so my thought was to create a class like stated above which gets the data off of the web-site then fills the datasets in the exact same manner that was done before.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 12677001
The issue will be in retrieving the data from the web service... in order to return anything resembling a database record, you'll have to return XML and then parse that back into the database.

However... if the database is accessible from the web server, then you can just use the OLEDB objects to hit the database. If you're using Access (which OLEDB suggests), you'll find that there are significant issues in trying to use it for multiple simultaneous users (i.e. a web app).

When you say "get the data off the web-site," are you referring to having a form submitted to the database?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:johnywhite
ID: 12682539
That is not the problem.  I can do that just fine and I have already written the code to do so.  Maybe I can explain this a little better.  With the code I have written I can fill the dataset like this.

Dim mywebservice as WebService1
Dim ds as New Dataset
ds = mywebservice.fill()

The web service is a function that returns a dataset, and that works just fine.  What I want to do is fill the dataset like this instead so I don't have to rewrite a lot of other code throughout my program.

Dim ds as New Dataset
Dim adapter as New JWDataAdapter("SELECT * From DB", connstring)
adapter.fill(ds, "DB")

Where JWDataAdapter is a class that I have written which calls the WebService and fills the dataset ds.  This is what I don't know how to do.  I am quite sure that it is something incredibly simple that I am missing, but I am not sure what that is.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 1000 total points
ID: 12695485
Sorry for the delay in answering. I was out of the office Friday afternoon.

If I understand correctly, you have a web service that you call with no arguments to fill a dataset, and want to find an easier way to return this dataset by using replace to avoid rewriting code? Okay... here goes.

1. Your arguments to the JWDataAdapter constructor are not going to be used. However, we'll leave them in and do nothing with them to avoid rewriting code.
2. Likewise, the arguments to the Fill method are unused.

Public Class JWDataAdapter
      Public Sub New(ByVal SQL As String, ByVal connString As String)

      End Sub

      Public Function Fill(ByVal SQL As String, ByVal connString As String) As DataSet
            Dim mywebservice As WebService1
            Dim ds As New DataSet
            ds = mywebservice.fill()
            Return ds
      End Function
End Class
0
 

Author Comment

by:johnywhite
ID: 12712935
I figured it out.  What I needed is to use ByRef instead of ByVal.  Like this:

Public Class JWDataAdapter
     Public Sub New(ByVal SQL As String, ByVal connString As String)

     End Sub

     Public Function Fill(ByVal ds As DataSet, ByVal table As String) As DataSet
          Dim mywebservice As WebService1
          Dim ds As New DataSet
          ds = mywebservice.fill()
          Return ds
     End Function
End Class

Then I can fill it like this:

Dim ds as New Dataset
Dim adapter as New JWDataAdapter("SELECT * From DB", connstring)
adapter.fill(ds, "DB")

Thanks for your help though.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month19 days, left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question