473,769 Members | 5,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database Application Example

Gav
I'm writing a windows application (using C# VS 2005 Pro) to access a MS SQL
database and although it is working fine (up to now) I'm not sure I'm going
about it in the best way. Can anybody point me to any good examples online
that i can look at, found loads of web applications but struggling to find a
good windows application example.

thanks

Gav
Oct 25 '07 #1
5 14274

"Gav" <ga*@nospam.com wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
I'm writing a windows application (using C# VS 2005 Pro) to access a MS
SQL database and although it is working fine (up to now) I'm not sure I'm
going about it in the best way. Can anybody point me to any good examples
online that i can look at, found loads of web applications but struggling
to find a good windows application example.
If you abstract the form from the data access, then it shouldn't matter what
the form Web or Windows is being used. The form should be decoupled from
data access with SQL Server.

http://msdn.microsoft.com/msdnmag/is...taAccessLayer/
http://www.c-sharpcorner.com/UploadF...egant_dal.aspx

I am sure you can find other examples using Google about the DAL.

You might also want to look into the UI/Business layer/Data Access layer
concepts

The UI uses a business layer object to access the data access layer object.
The UI never makes a direct call to the DAL or no direct calls to the
database. It goes through the business object.

You can do an even more abstraction of the UI from all other layers by using
MVP concepts. No reference to the BL at all from the UP, the UI goes through
the presentation layer to the BL and BL to the DAL, using interfaces. The UI
should be unaware of the BL. You return all properties of the BL object on
the MVP interface. If you need to bind data from SQL server to a control,
then you use a DataTable as the return type through the MVP interface, as an
example from the BL/DAL objects. No BL object and it's properties should
ever be addressed at UI.

UI/MVP/BL/DAL.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

You should also understand an object's Public accessor properties of Get/Set
in C#.


Oct 25 '07 #2

http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!140.entry

Download the source code.

Basically, replace the "Program.cs " with a new Folder, like
"Presentation.W informs" (aka, create a new folder, and put your form files
in there)
and you'll have a NLayered application.

In my demo, the console application is the "presentati on layer", as crappy
as it is.

The code-behind of your buttons (on any of your forms) shouldn't know
anything about database connection strings, sqlcommand, sql connection
objects.
They should know about the BusinessLayer.

You might want to get the 1.1 version of the project above:
http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!139.entry

because there I think I seperate out the layers into different assemblies.
The second link also has a VERY GOOD MS link at the bottom. Go find that
article and read it, reread it a few times.

"Gav" <ga*@nospam.com wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
I'm writing a windows application (using C# VS 2005 Pro) to access a MS
SQL database and although it is working fine (up to now) I'm not sure I'm
going about it in the best way. Can anybody point me to any good examples
online that i can look at, found loads of web applications but struggling
to find a good windows application example.

thanks

Gav

Oct 25 '07 #3
Gav

"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:ed******** ******@TK2MSFTN GP02.phx.gbl...
>
"Gav" <ga*@nospam.com wrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>I'm writing a windows application (using C# VS 2005 Pro) to access a MS
SQL database and although it is working fine (up to now) I'm not sure I'm
going about it in the best way. Can anybody point me to any good examples
online that i can look at, found loads of web applications but struggling
to find a good windows application example.

If you abstract the form from the data access, then it shouldn't matter
what the form Web or Windows is being used. The form should be decoupled
from data access with SQL Server.

http://msdn.microsoft.com/msdnmag/is...taAccessLayer/
http://www.c-sharpcorner.com/UploadF...egant_dal.aspx

I am sure you can find other examples using Google about the DAL.

You might also want to look into the UI/Business layer/Data Access layer
concepts

The UI uses a business layer object to access the data access layer
object. The UI never makes a direct call to the DAL or no direct calls to
the database. It goes through the business object.

You can do an even more abstraction of the UI from all other layers by
using MVP concepts. No reference to the BL at all from the UP, the UI goes
through the presentation layer to the BL and BL to the DAL, using
interfaces. The UI should be unaware of the BL. You return all properties
of the BL object on the MVP interface. If you need to bind data from SQL
server to a control, then you use a DataTable as the return type through
the MVP interface, as an example from the BL/DAL objects. No BL object and
it's properties should ever be addressed at UI.

UI/MVP/BL/DAL.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

You should also understand an object's Public accessor properties of
Get/Set
in C#.

Thanks for your detailed reply to my question. I've watched the podcasts
they are great. I get the point of splitting things down to make changes and
testing easier but I'm a little confused over persistence.

For example in my application (winform) after opening the main window a user
can choose to login to the application, at which point a popup opens asking
the user to login. Then I populate my User class with various authorisations
etc and use it for the remainder of the time the user is logged in. I'm not
sure how I would do this using the MVP model, where would my User class be
and how would it be referenced? Looking at the examples so far the (if i'm
understanding them correctly) each windows Form has reference to a
particular view class and the view class has reference to the business logic
classes. So on changing forms the instance of the User class would no be
visable.

This is all new to me so I may be missing something obvious, or just be
completely wrong in my understanding so far. :o)

Gav
Oct 29 '07 #4

"Gav" <ga*@nospam.com wrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>
"Mr. Arnold" <MR. Ar****@Arnold.c omwrote in message
news:ed******** ******@TK2MSFTN GP02.phx.gbl...
>>
"Gav" <ga*@nospam.com wrote in message
news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>I'm writing a windows application (using C# VS 2005 Pro) to access a MS
SQL database and although it is working fine (up to now) I'm not sure
I'm going about it in the best way. Can anybody point me to any good
examples online that i can look at, found loads of web applications but
struggling to find a good windows application example.

If you abstract the form from the data access, then it shouldn't matter
what the form Web or Windows is being used. The form should be decoupled
from data access with SQL Server.

http://msdn.microsoft.com/msdnmag/is...taAccessLayer/
http://www.c-sharpcorner.com/UploadF...egant_dal.aspx

I am sure you can find other examples using Google about the DAL.

You might also want to look into the UI/Business layer/Data Access layer
concepts

The UI uses a business layer object to access the data access layer
object. The UI never makes a direct call to the DAL or no direct calls to
the database. It goes through the business object.

You can do an even more abstraction of the UI from all other layers by
using MVP concepts. No reference to the BL at all from the UP, the UI
goes through the presentation layer to the BL and BL to the DAL, using
interfaces. The UI should be unaware of the BL. You return all properties
of the BL object on the MVP interface. If you need to bind data from SQL
server to a control, then you use a DataTable as the return type through
the MVP interface, as an example from the BL/DAL objects. No BL object
and it's properties should ever be addressed at UI.

UI/MVP/BL/DAL.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

You can use Google to get more information about this or find books.

You should also understand an object's Public accessor properties of
Get/Set
in C#.


Thanks for your detailed reply to my question. I've watched the podcasts
they are great. I get the point of splitting things down to make changes
and testing easier but I'm a little confused over persistence.

For example in my application (winform) after opening the main window a
user can choose to login to the application, at which point a popup opens
asking the user to login. Then I populate my User class with various
authorisations etc and use it for the remainder of the time the user is
logged in. I'm not sure how I would do this using the MVP model, where
would my User class be and how would it be referenced? Looking at the
examples so far the (if i'm understanding them correctly) each windows
Form has reference to a particular view class and the view class has
reference to the business logic classes. So on changing forms the instance
of the User class would no be visable.

This is all new to me so I may be missing something obvious, or just be
completely wrong in my understanding so far. :o)
Your User class is a Business object or object model that's actually at the
Business Layer. The UI should be unaware of the Business object. Your
solution should be loosely coupled in that regard. That means that there
should not be a reference to the Business layer if at all possible from the
UI layer. This is not a hard and study rule, but it is one that you should
follow as much as possible.

So with that said, you extract everything from the User class that is needed
and you bring like type fields back through the MVP Interface, string
UserName to Public Interface string.Username { set; }. You bring everything
back field by field.

Then at the UI at the UserName interface, you're going to use the Set value
and set (private string username) from the value of the returned Interface
field, as an example. You bring it all back through the MVP Interface field
by field.

Again, the UI should be unaware of a model object/Business object.

That Service Layer example is using a Business Object Reference and a <List>
to bind it to a control at the UI with a reference to the BL at the UI. But
you don't need that Service Layer, if you don't want to use it.

You can use a Dataset and DataTable and bring that DataTable back from the
DAL through the BL and through the MVP Interface as a DataTable back to the
UI and bind the DataTable to the control at the UI, with out the Service
layer. In this way, the UI still knows nothing about the BL or a model
object.
Oct 29 '07 #5

This demo about Login may help you too.

http://www.codeproject.com/useritems/mvpBasicDemo.asp
Oct 29 '07 #6

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

Similar topics

8
2152
by: BMM | last post by:
Hi. I have a dumb question. Is a database an application? And, in the context of a data-driven web-enabled application, is the database still an application? I have a project lead who says it is. In fact, he says that our web application is a set of "distributed applications" because * the database is an application, and * clients connecting to our web app will connect with a web browser (an application) and may put data pulled from the...
18
4618
by: mountain man | last post by:
Greetings to all database professionals and laymen, Let us make a bold assumption that we have developed a software tool for the SQL Server environment which simply acts as an interface between an end-user in an organization and the database, through the exclusive use of stored procedures which are authored by the organization or by software developers. All development work at the application software level may thereby be conducted...
9
9478
by: Big Slim | last post by:
I'm working on a web application that makes heavy use of CSS, but I would like users to have a degree of control over some of the classes and attributes. To accomplish this, I want to store my CSS classes in a SQL database. The only problem is, I'm having a heck of a time trying to design the database tables in a normalized way. I have searched high and low for examples of CSS entity-relationship diagrams--to no avail. Has anyone here...
4
1579
by: DevinG | last post by:
I would like to first start off saying that this is pretty much my first week of heavily getting into ASP.net. I previously have programmed in ASP Classic, and now understanding the benefits of ASP.net I would like to cross over. Anyways onto my question. I am curious how i can go about setting up a class with the connection to my database in it, which any page can use to connect to that database. I was never heavily in classes or...
0
2593
by: mel_apiso | last post by:
Hi, after uncatalog one database, and catalog again with other name, if I try to connect with this database, everything is ok, but list applications only show me the connection with the uncatalog/catalog database. After I disconnect from this database, list applications command show all instances connection. Below I paste the situation.
16
1370
by: Marcos de Lima Carlos | last post by:
Hi all, I have a VB aplicantion in many places. I need to manage databases over files on pen drive. What's the database i using to manage this program? My conditions is this: i have most computer but it's not conected to internet and i have to actualize this database in a server-computer. tks a lot, Marcos
6
5892
by: Ted | last post by:
I am construvcting a number of databases, some of which contain sensitive data and most of which do not. I am attempting to handle the security issues involved in protecting sensitive data in part by putting it in its own database. If the sensitive data is in a database called d_SensitiveData, and in that database there is a table called 't_A' (I know, not very informative, but this is only a trivially simple example :-), and I have a...
22
60282
Frinavale
by: Frinavale | last post by:
How To Use A Database In Your Program Many .NET solutions are database driven and so many of us often wonder how to access the database. To help you understand the answer to this question I've provided the following as a quick example of how to retrieve data from a database. In order to connect to a SQL Server Database using .NET you will need to import the System.Data.SqlClient package into your program. If you are not connecting to a...
12
7017
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a foreign Key relationship or does this always indicate some sort of underlying design flaw. Something that requires a re evaluation of the problem domain? The reason I ask is because in our application, the user can perform x
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9860
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
8869
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
6668
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
5297
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
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
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
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
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.