EDIT: If you would prefer to watch this as a video go to this link: Basic Data Binding In C# | Screencast-O-Matic
Basic Data Binding in C#
Step 1: Create a new windows C# form and name it contactBookV1
Step 2: (Optional) Size your form up a bit by clicking on it in the design window and dragging it up and out
Step3: (Optional) Select the form in the designer and change the text filed in the properties window to “Contact Book V.1” This will change the text at the top of the form
Step4: Create a new Data base by going to Project >> Add New Item
Step4 (Continued): Chose Service-Based Database and name it MyContacts.
Note: Hit the Cancel button on the Data Source Configuration Wizard.
Step5: Right Click on Tables in the Server Explorer Pane (Database Explorer if you are using Express addition) and Select Add New Table from the submenu
Step6: Create your Table by following the below Schema
Note: Set Primary key by selecting the desired cell and hitting the key up on the menu
To make it Auto Increment, go to the Column Properties, Under Identity Specification, set (Is Identity) to yes.
(If the c_id filed is not set up correctly your program will crash when you try to use certain features)
Step7: On the menu under file select Save All. Name the database contacts.
Step8: Create a new Database Diagram by right clicking the database diagram in the Server / Database Explorer and selecting new Diagram
The below window will pop up. Select “Yes”
A new table will pop up titled “Add Table” Select Contacts from the list and hit Add
Save the Diagram as contactsDiagram
Step9: Go back to the Form1.cs *design* tab. From the menu bar select Data >> Add New Data Source
Select Database from the new popup window. Proceed to hit the next button until you get to the final page. On the last page check all the check boxes and hit finish.
Step 10: Go to the Data Source Pane and expand the field called Contacts so that you see all the cell names from your database. click on Category and then click on the silver down arrow that appears next to it. Select Combo box from the menu that appears.
Step11: Left Click on each filed in turn and drag it onto the windows form (Do not put c_id on the form) and put them in some type of pattern. You can change the lable to each control the same way we changed the forms text in Step 3 (Note: Make sure you select the lable [Black text] Not the text box [white box])
Your form should now look like this:
Step12: left click the combo box for category on your form. Chose Items from the properties pane and enter in the values Friend, Business, and Other then hit OK button
Step13: Save your work and hit F5, everything should work except saving. You will have to Create a setup to do that.
Step14: Time to create that install so everyone can use your application. Select Build on the menu than select Publish contactBookV1 from the submenu.
Hit finish on the window that pops up to accept all the defaults.
Inside your project folder you will find a folder called Publish. Grab all of its content and copy it to a disk. Go install it on a computer and go crazy ^_^
(Ehh I think I got all the images in the right spot. If every thing wasnt clear I apologise, this is my first tut.)


LinkBack URL
About LinkBacks
























Reply With Quote







Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum