473,834 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design question --- Return a DataSet?

JS
I'm trying to create a data layer and having problems returning a DataSet
from my code that's in a class module.

Please forgive me. I'm new to C# (VB'er). I decided to create my data layer
in small steps. Right now, I'm just trying to attach a ComboBox to a dataset
that's in my class module. In the class, I call a Stored Procedure. I know
how to set up the connection, command, adapter, and dataset, what I'm having
a problem with is, telling the method in my class to return the dataset to
the caller.

In VB I could return the dataset by creating a function like such:
This code is in a class module.

Function ShowVendors() as DataSet
Connection
Command code
Adapter code

Return myDataSet
End Function

I then set the ComboBox datasource to ShowVendors(). Works like a charm.
But, I cannot for the life of me get ShowVendors() to return the dataset
back to the caller in C# I have seen and tried a million examples (give or
take a hundred or so) examples on how to bind a control to a dataset, but I
don't know how many more "Console.WriteL ine" or code behind the form
examples I can take. I want to keep all of my database connections totally
separate from my forms.

So, I guess my question is two part. How do I return a dataset from my data
layer, and is returning a dataset like I'm trying to here a good or bad
design approach?

Any help on this would be greatly appreciated. TIA,

- JS -
Nov 15 '05 #1
2 13059
Hi,

As for design issues, I think it would be better to return a DataTable - as
you don't need data relations and multiple tables. But as for coding, there
is no big difference in returning either a DataSet or a DataTable (both ways
are simple like 1,2,3):

using System;
// You might need to add a reference to System.Data.dll to your
// project.
using System.Data;

namespace MyDataLayer
{
public class MyDataObject
{
// Constructors, class members and other stuff...

public DataSet GetCustomers()
{
DataSet customers = new DataSet();

// Create connection, command, data adapter, whatever to populate the
dataset.

return customers;
}
}
}

In the example above, you can easily replace DataSet with DataTable. Hope
this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"JS" <no*****@northe re.com> wrote in message
news:Jl******** ************@co mcast.com...
I'm trying to create a data layer and having problems returning a DataSet
from my code that's in a class module.

Please forgive me. I'm new to C# (VB'er). I decided to create my data layer in small steps. Right now, I'm just trying to attach a ComboBox to a dataset that's in my class module. In the class, I call a Stored Procedure. I know
how to set up the connection, command, adapter, and dataset, what I'm having a problem with is, telling the method in my class to return the dataset to
the caller.

In VB I could return the dataset by creating a function like such:
This code is in a class module.

Function ShowVendors() as DataSet
Connection
Command code
Adapter code

Return myDataSet
End Function

I then set the ComboBox datasource to ShowVendors(). Works like a charm.
But, I cannot for the life of me get ShowVendors() to return the dataset
back to the caller in C# I have seen and tried a million examples (give or
take a hundred or so) examples on how to bind a control to a dataset, but I don't know how many more "Console.WriteL ine" or code behind the form
examples I can take. I want to keep all of my database connections totally
separate from my forms.

So, I guess my question is two part. How do I return a dataset from my data layer, and is returning a dataset like I'm trying to here a good or bad
design approach?

Any help on this would be greatly appreciated. TIA,

- JS -


Nov 15 '05 #2
JS... I've wrapped up a few data classes that return objects as you're
trying to do as well as completely separate the data acquisition from
the presentation. Your form only needs to know what a datatable or
datareader is... nothing beyond that.

You're welcome to download and use them as they are or use them as a
starting point or reference for creating your own. They're not
all-inclusive, but they work for many of the projects I've worked on
and used them in.

http://www.chornbe.com/softdownloads.aspx then click on DBTools

I hope that helps.

"JS" <no*****@northe re.com> wrote in message news:<Jl******* *************@c omcast.com>...
I'm trying to create a data layer and having problems returning a DataSet
from my code that's in a class module.

Please forgive me. I'm new to C# (VB'er). I decided to create my data layer
in small steps. Right now, I'm just trying to attach a ComboBox to a dataset
that's in my class module. In the class, I call a Stored Procedure. I know
how to set up the connection, command, adapter, and dataset, what I'm having
a problem with is, telling the method in my class to return the dataset to
the caller.

In VB I could return the dataset by creating a function like such:
This code is in a class module.

Function ShowVendors() as DataSet
Connection
Command code
Adapter code

Return myDataSet
End Function

I then set the ComboBox datasource to ShowVendors(). Works like a charm.
But, I cannot for the life of me get ShowVendors() to return the dataset
back to the caller in C# I have seen and tried a million examples (give or
take a hundred or so) examples on how to bind a control to a dataset, but I
don't know how many more "Console.WriteL ine" or code behind the form
examples I can take. I want to keep all of my database connections totally
separate from my forms.

So, I guess my question is two part. How do I return a dataset from my data
layer, and is returning a dataset like I'm trying to here a good or bad
design approach?

Any help on this would be greatly appreciated. TIA,

- JS -

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2328
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup windows where you can edit information and data, nothing out of the ordinary. I estimate we have something like 50 to 100 tables and/or views in our database each of which map to one strongly typed DataTable. Now we have some odd 20 to 30 typed...
2
1740
by: muesliflakes | last post by:
I have a DataSet that bound to controls on multiple forms. Currently an instance is created on each form and Load / Write is handled on each form. Instead I would like to have a single instance DataSet that is accessed and maintained by Data Access Object (DAO) and I would like that DataSet to be re-used on each form. The problem I have is that when I drag a DataSet component onto a form, I am having trouble linking it to the DataSet...
9
6265
by: Hasan O. Zavalsiz | last post by:
Hi , i am trying to figure out which approach is better to use . let me explain the scenario. i am using the "Nortwind" database . in this database i have "Customers " table .The following is the two different ways to handle this table. CASE 1 : create a struct that encaplusates table "Customers" columns public struct structCustomers { public string CustomerID;
10
2141
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post shouldn't be here). I have two design questions: 1. what is the correct (or best) way to include database queries into the code if you plan on
6
2123
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
2
1867
by: Matthew Hood | last post by:
My company has expressed a desire to convert an existing MS Access application to a full VB.NET application. My experience is with VB6 so I want to ask a few questions and get some input on the best way to handle the following design: Situation: We want to allow our customers to install with one of the following options: 1. Use an Access MDB file as the data backend. 2. Use a SQL Server backend. (Either MS SQL, or MySQL) 3. Use an...
3
1377
by: John S | last post by:
I've got to produce a console app that requests a dataset from a web service in our personnel system, manipulates the data and then updates each record in the Active directory. Not being the most brilliant OOP programmer I'm having problems trying to design suitable objects. Would anyone like to suggest how they would design this type of app? Thanks
0
2086
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the end of this message, but I will start with an overview of the problem. I've made a content management solution for my work with a decently structured relational database system. The CMS stores articles. The CMS also stores related items --...
8
4141
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well. However i have recently started a project which will require synchronization to a remote database. Also the underlying database provider may change at a later date. From what i have read it seems that a layered approach is necessary, or at...
0
9646
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10793
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10219
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6954
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.