Using ADO.NET in Windows Forms


S

sheperson

Hi,
I have always had a problem when programming with ADO.NET and Windows
Forms.
It is about how to access database through WinForms. For example I
have an application with several forms and each form deals with a part
of the database. There are some options available:
1- I can create a dataset in the main Form, fill it with data from
the database, and then pass it to other child forms as an argument.
The child forms do what they want with the dataset and at the end, the
main Form updates the database with the new information.

2- Each form has it's own dataset, connects to the database, fills the
dataset and then updates the database when it wants to be closed.

But non of the above approaches are good.
I wonder if anyone has an idea about it.
Thanks in advance.
 
Ad

Advertisements

D

Devin

Hi,
I have always had a problem when programming with ADO.NET and Windows
Forms.
It is about how to access database through WinForms. For example I
have an application with several forms and each form deals with a part
of the database. There are some options available:
1- I can create a dataset in the main  Form, fill it with data from
the database, and then pass it to other child forms as an argument.
The child forms do what they want with the dataset and at the end, the
main Form updates the database with the new information.

2- Each form has it's own dataset, connects to the database, fills the
dataset and then updates the database when it wants to be closed.

But non of the above approaches are good.
I wonder if anyone has an idea about it.
Thanks in advance.

As an alternative:

You could create a separate class with in the same namespace that
contains the dataset as a static member. That way you will only have
to fill it once and use it/update it where ever you needed to.

Devin
 
M

Mr. Arnold

Hi,
I have always had a problem when programming with ADO.NET and Windows
Forms.
It is about how to access database through WinForms. For example I
have an application with several forms and each form deals with a part
of the database. There are some options available:
1- I can create a dataset in the main Form, fill it with data from
the database, and then pass it to other child forms as an argument.
The child forms do what they want with the dataset and at the end, the
main Form updates the database with the new information.

2- Each form has it's own dataset, connects to the database, fills the
dataset and then updates the database when it wants to be closed.

But non of the above approaches are good.
I wonder if anyone has an idea about it.
Thanks in advance.

As far as I am concerned, it's poor design concept. The only thing you
should be doing with a dataset at the UI is to fill a grid, combox
listbox --- a read only situation. Maybe, the information below will give
you some guidance.


MODEL-VIEW-PRESENTER
http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns'

view part 1, 2, 3, 4, 5
 
S

Saimvp

Hello my friend. try this and I hope it can help.


//create dataset function

public static DataSet Execute(string Sql)
{
OleDbConnection CON = new OleDbConnection();
CON.ConnectionString = "YOUR CONNECTIONSTRING";
CON.Open();

OleDbCommand cmd = new OleDbCommand(Sql, CON);

DataSet ds = new DataSet();

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
return ds;
}

// THEN AT YOUR FORM1 LOAD

//declare a string
string MYstring = "select * from
";

//set datasource for you gridview
datagridview.datasource= YOURCLASS.execute( MYstring ).tables[0];
 
Ad

Advertisements

S

sheperson

As far as I am concerned, it's poor design concept. The only thing you
should be doing with a dataset at the UI is to fill a grid, combox
listbox --- a read only situation. Maybe, the information below will give
you some guidance.

MODEL-VIEW-PRESENTERhttp://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns'

view part 1, 2, 3, 4, 5

Thanks so much. It took along time to download those shows using my
dial-up connection!!!.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top