free counters




  • If you landed here, that means you either read the book or searched the internet for VS-2010 database connection, either ways, you've landed in the right place.
  • In the book; the photos show how to start your project, how to select your database and how to display it. Here, we'll discuss each photo and explain each code block.
  • Photo (1) : Shows the folder that contains the project, the (My-First-Con.vbproj) is the icon you need to click to open the project.
  • Photo (2) : From menu (Data) choose (Add New Data Source), a popup dialog-box will show titled (Choose a Data Source Type) and you select (Database) as long as we are connecting to one, then click next.
  • Photo (3) : A popup dialog-box appears titled (Data Source Configuration) and you select (DataSet). The DataSet is the connection type we are trying to establish here, click next. Also in the end you will notice a file (DataSet) was created, let's not rush, ok?!
  • Photo (4) : Another dialog-box shows up titles (Choose Your Data Connection), here we'll choose (New Connection) and another dialog-box will show up to choose the connection from it, this new dialog-box titled (Add Connection) has (Change) button and (Browse) button, we will click on (Change) to choose the data source we wish to work with, as for this lesson we're working on (Access) so we will choose access from the next popup window that will show when we click on (Change) which called (Microsoft Access Database File), the other databases are for the other types of databases, now choose (Access) and there will be another button below called (Data Provider) which provides us with the technology we wish to work with, as for here we will work with (.Net Framework Data Provider for Ole DB), then we click next.
  • Photo (5) : Back to the (Add Connection) Dialog-box with new data where (Data Source) field is (Microsoft Access Database File (OLE DB)) and we choose the database name from (Browse), we navigate to the pre-created access2007 file in (E:\My-First-Con\bin\Debug) folder then ok, we will find the full path showed in the (Database Name) field, leave any other fields as it is, you may choose to (Test Connection) or not, anyway in the end click OK.
  • Photo (6) : Back to the (Data Configuration Wizard) but this time the (Which Data Connection ...) field filled with (First.accdb) which is out database name and the (Connectio String) field is filled with the full string that represents the database connection to this database using .Net Framework for OleDB Tech, and we click next
  • Photo (7) : Popup message from VB2010 ("The connection you selected uses a local data file ..... etc"), i've put the database file in the first step in the (bin\) directory to show this message box, because there is a default folder for the database file where the database file should be located and stored in it which is - according to our lesson - and generally (E:\My-First-Con\), so everytime you place a database in your VB2010 project, please place it there (The Main Folder Where Your .vbproj File Is Located), coz it also will save you a block of code and path problems we'll discuss that later, now click (No) then (Back). From
    (Add New Connection) select the database file (First.accdb) from the previous path (E:\My-First-Con\), you will notice that VB2010 already copied it there, if you tried to delete the old one in the (bin\) directory the Windows won't let you coz it's already still openned so just let it go now and click (OK) The (Add Connection) window disappears.

  • Photo (8) : The window (Data Source Configuration Wizard) will show where you will notice that the (Connection String) field has changed to the new path, now click next with no VB2010 warning messages.
  • Photo (9) : New window will show asks you to (Save The Connection), so we'll save the connection but we will rename it to (MyFirstCon) and keep the checkbox checked, notice in the (Solution Explorer) a new item was created called (First.accdb) that means that the project is now familiar with your database file, click next.
  • Photo (10) : Another window will show up asks you to choose your (Database Objects) which are the Tables and the Views, we already have created one Table called (Info) so we'll choose it, along with its fields as shown in the photo, rename the (Data Set name) to (MyDS) and click finish.
  • Photo (11) : Notice the (Solution Explorer) Window, (Data Source) Panel and the (Project Main Folder Files).
  • Photo (12) : From the (Data Source Panel) grab the object (Info) with the mouse and drop it on the form, resize your form to show all the table .
  • Photo (13) : From (Run) or press (Ctrl + F5) from your keyboard to run the project, you will find that you are successfully connected to (First.accdb) database, congratulations.
    Save your project (Ctrl + S) and close it (Ctrl + F4), remove the old database file in the old path (E:\My-First-Con\bin\Debug\), reopen your project and use the toolbar up in the form to perform (Add - Save - Delete - Navigation) to the database table (Info).
  • Display changes you've made to the database table while running the project by closing the form and reopen it again.



Kasino på nett

Back


All contents are CopyRight © ® ™ to Evry1falls

Free Web Hosting