Creating a DB project in VB

  • Create a new windows form project.
  • Select Project – Add New Data Source //this brings up a dialog box which will let you select the database file you are to work with and to create a new dataset – the data the program will play with.
  • Select the database icon and then Next
  • Select the dataset icon and hit Next
  • The next form will allow you to set up your connection string, which dictates all the system needs to know to connect – the type of database, where it is at, etc.
  • Choose your data connection. If you already connected to this DB it may already list that database, otherwise select “New Connection”.
  • Choose the database type. For Access, choose “Microsoft Access Database” and click OK. You will return to the prior screen, and Data Source will now list Microsoft Access Database File OLE DB
  • Browse to find your DB file.
  • Do NOT put in a password, leave blank so that I can work with your database.
  • Test Connection. This will make sure it can find the database and gain access to it.
  • On the original screen, your database name will now show up , and a “Connection string” box is there. If you click on that, you can see the actual string that it is using for your database.
  • Normally, you would say “No” because then a new copy of the DB is created in the bin folder in your project and not to the original database. For ours, this might solve the problem of the database being in a different directory.
  • The next screen shows you the default name the system will use for the connection string which you will be able to access in your program. Mine says “SailorsConnectionString”.
  • The next screen asks what you want to connect to. If you have a query result or specific tables, select those. I selected both/all.
  • We now have a “SailorsDataSet”, which will be the data we can access and plan with.
  • When completed, go to Solution Explorer, and you should see your database icon and name, and a new file called “Sailorsdataset.xsd”. This is a typed dataset which includes XML code for all the fields and tables which we will be able to use.
  • Right Click on this file, and select “View Designer” which gives us a designer to create bound components that will be on your screen.
  • You can click on a single field in this view, and in the properties box, you can set certain properties, like maximum width
  • Creating data bound objects using Data Sources and drag-and-drop
  • Open the Data Sources window by selecting : View – Other Windows – Data Sources. You will see the tables and queries from the dataset. Click on each table to see the fields. For each field you would like to add to the form, select the type of data object you want it to be displayed in.
  • When done, drag each of them to the design form.
  • Run the program, and the data should now show up and automatically a data Navigator has been added. I moved mine to the bottom of the screen, which is a more natural place for it.
  • Creating SQL views using a Query Builder –
  • Click one of the little arrows on the box to get the Query Builder up. Select the new query and then choose Query Builder to work on the SQL.
  • Code the SQL statements into the text editor, adding the tables you need. If you set up the relationships in ACCESS, this part will be coded for you in the SQL statement
  • Add the additional features you want and then Execute the query to be sure you get those things you need
  • Click OK, then click OK on the first form. You should now see this create a button for you that will enact this query when you want to.