newbie - public available dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ,

i am fairly new to c# and programming and here is my question!

i have a dataset to store information in a windows form project. At the moment it is made and loaded in the MainForm method. Now i want to add a record via a button click event. How do i access the dataset in the click event or if i use a function, how do i send the dataset as a parameter to the function?

I hope anybody understand what i try to do. Perhaps there is a better way to implement this in C#.

Any comment or idea is welcome!
 
You can try out the following methods to try databinding using a dataset.

(1) Use DataForm Wizard to create a new data bound form by following the wizard steps. Then study the properties of the controls that are created by the wizard on the form, especially the (DataBinding) section of properties at the top of properties window. Also study the code generated, which will give you a complete idea of how data binding works. This wizard is found in Project --> Add Windows Form.

When text boxes and other controls (e.g. list boxes or labels) are data bound, whatever changes are made to the text of textboxes is saved to the database when user clicks on the update button.

Note that there are two types of datasets -- typed and untyped. The one created with the wizard is a typed one. Same you can achieve using the data tab of the toolbox. Follow the following steps:
(1) Double Click DataAdapter (SQL or OLEDB) in the toolbox and follow the wizard steps.
(2) Right click DataAdapter in the components tray and click on Generate DataSet.
(3) Create textboxes and other controls on the form corresponding to the database table columns. Create buttons, Load and Save
(4) Use the DataBindings section of textbox properties to bind it to a column of dataset table.
(5) Use dataset.Fill() method to load the dataset
(6) Use dataset.Update() method to save changes
(7) dataset.AddNew() for adding a new blank record and dataset.Update() to save the new record.
(8) For scrolling through the records, you have to create prev, next buttons and use BindingManger object. (Refer to the DataForm wizard generated code wherever you face problem)

Hope this helps.
 
Hi,

Dataset is a reference type - this means that when you pass it around as a
parameter, only a reference to the actual dataset is passed. References are
some 4 bytes in size, so no need to be worried about the performance.

However, in your scenario, it would be better to make the dataset a private
member of the form:

private DataSet m_dataSet;

and then use it in any method of the form class.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Thorsten moeller said:
Hi ,

i am fairly new to c# and programming and here is my question!

i have a dataset to store information in a windows form project. At the
moment it is made and loaded in the MainForm method. Now i want to add a
record via a button click event. How do i access the dataset in the click
event or if i use a function, how do i send the dataset as a parameter to
the function?
 
Back
Top