473,757 Members | 8,356 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 13056
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
2317
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
1739
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
6263
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
2137
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
2118
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
1864
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
1374
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
2080
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
4134
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
9298
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
10072
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...
0
9737
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
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
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
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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.