Search:: A Really Simple Database
Search:: A Really Simple Database
Search:: A Really Simple Database
Forums
Programming
Web Development
Computers
Tutorials
Snippets
Dev Blogs
Jobs
Lounge
Login
Join!
Today's Topics
Dream.In.Code
> Programming Tutorials
> VB.NET Tutorials
(2 Pages)
1
2
→
D.I.C Regular
Reputation: 38
Posts: 396
Joined: 02-June 07
POPULAR
Hi All
In this tutorial I will explain how to make a really simple database using a Microsoft Access
database in conjunction with VB.net Express 2008. The way the application is constructed
requires minimal effort as we will utilize the capabilities of the VB.net Express IDE. This
tutorial is aimed at people who are new to programming; I have assumed you have got a basic
Knowledge of Microsoft Access, here goes.
1. Create a folder on you C drive or where ever you like just remember the path, for this example
I used C:\Database. Add three photographs to this file in a JPG format.
2. Open access and create a blank database called DB1 and save it in your database file. Create a
table in design view and add 4 fields
[ClientID] Data type = Auto Number. Set this as the primary Key
[FirstName] Data type = Text
[LastName] Data type = Text
[Picture] Data type = OLE Object
Save the table with the name Clients. Open the table and add this data into the first and last name
fields don’t worry about the picture field.
Peter Jones
David Smith
Jane Doe
3. Open the VB express IDE and select File and New project. Select Windows forms
Application and name it MyaccessDB press OK. You should now have form1 in your IDE
4. The next step is to add our data source to our project. On the left-hand side of the IDE select
the Database explorer window, right click on the Data Connections and select Add connection.
In the Add connection window select Microsoft Access Database File (OLE DB), and then
browse to find our access database and select. Ignore the password and test the connection which
should work. Press OK you should now have our DB1.mdb Database in our Data connections
window.
Expand the database and then expand the tables folder you should now see the Clients table.
5. We next have to add a dataset to the project in the solutions explorer. Right click on
myaccessDB and select Add then New Item. Select Dataset and then Add. You should now
have a dataset in the solutions explorer and the Dataset1 tab will be open.
6. We need to add the Clients table to the Dataset, we do this by selecting the Clients table in the
data connections window and drag the table onto the Dataset1 tabbed page.
You should now have a Clients Table Adaptor in the Dataset with an SQL fill query at the
bottom of the table which has been automatically generated. Save the Dataset
Note: You should get a message at this point asking if you would like to copy a file to your
project click Yes.
7. We now need to add the Dataset1 to the form. In the main area of the IDE select Form1. In the
solutions explorer open the Data sources window. Expand the Dataset1 to show the clients table,
highlight the clients table and from the drop down menu select details. Expand the clients table
and highlight the Picture field and from the dropdown menu select Picture box. Now highlight
the clients table and drag onto the form1. You will see appear automatically textboxes; labels a
picture box and a binding navigator on the form. You now have a working database. Run the
application and page through the records you have entered. You can now also Add, Delete and
Save records
Although at this point we cannot show a picture which is next.
8. from the tool box select a button and drag it onto the form, call it Load Picture, double click
the button to open the code editor and paste this code into the buttons sub.
This code is used for the open file dialog which we use to select the picture we want to show
Run the application and press the load picture Button. Navigate to the database file and select a
picture. Close the dialog box and press the save button on the Navigator strip, the picture will
now be stored in the access database. Repeat this for all the records pictures.
Note: You may need to expand the picture box and play around with the settings to make the
pictures look right.
And there we have it a fully functional database, if you open up the code editor you will see how
little code is required to achieve what normally takes hundreds of lines of code which I think is
pretty cool and its quick, although there is a lot more code required to make sure the data entered
is correct and indeed all the required fields are filled in. The one thing that is missing is the
ability to search the database using wild cards which I am now going to cover.
9. Drag another button onto form1 and name it Search. Double click the button to enter into the
code editor page and add this line of code.
1 Form2.Show()
10. In the solution explorer add another form (Form2) and then add another dataset (Dataset2).
Keep the dataset2 tap open and drap the client table from the DB1.mdb in the Database Explorer
on to the dataset2. Again you will see the client table adaptor with the automatically create SQL
fill query at the bottom of the table. We will have to edit this query to enable the wild card search
facility.
11. Right click on the table adaptor and select Configure, the table adaptor configuration wizard
will open. You will see the actual SQL Select query. Click Query builder. In the query builder
page scroll down to the lastName record and then scroll across to the input box that says filter,
Place a ? in this filter box then press Ok to close the query builder.
Keep pressing next then Finish to exit the configuration wizard. The SQL query should now look
like this
Fill,Getdata(LastName)
Note: If you require further filters just add more ? marks in the other fields Filter box.
12. Open the form2 tab and click into the datasource window to show the datasets 1 & 2. Again
expand the Dataset2 and Highlight the Clients table, in the drop down menu select Details. Again
expand the clients table and highlight the picture field and from the drop down menu select
picturebox. Then just highlight clients table and drag onto form2. You should see again
textboxes, labels a picture box and a binding navigator appear on the form with the addition of a
fill tool strip with a LastName textbox and fill button.
Run the application press the Search and type a second name into the fill tool strip text box and
press fill, you should have 1 record shown.
And there you have it a fully functional database with possibly the smallest amount of code used
which is the main aim of a good programmer. Although it is neccasary to add more code to to do
conditional checks etc. You can also add in combo boxes instead of the Lastname text box you
just need to alter the client Table adaptor to suit see below :-
Me.ClientsTableAdapter.Fill(Me.DataSet2.clients,
1
LastNameToolStripTextBox.Text)
2
3 Me.ClientsTableAdapter.Fill(Me.DataSet2.clients, combobox1.Text)
Just as a footnote I have used an access database however you can add an MS SQL database to
your project by right clicking the project in the solutions explorer and add new item add Service
based database. The database explorer will be populated with the database you have created
where you can add your table and fill it with data. but I will leave you to figure this one out.
Quote + Reply
MrCupOfT
Reputation: 2298
Posts: 9,535
Joined: 29-May 08
Posted 29 November 2008 - 03:09 PM
Quote + Reply
#3 sharpy
D.I.C Regular
Reputation: 38
Posts: 396
Joined: 02-June 07
Quote + Reply
#4 abayomi
New D.I.C Head
Reputation: 0
Posts: 12
Joined: 19-May 08
This tutorial is really very good and it has helped me a lot. Many thanks
Was This Post Helpful? 0
Quote + Reply
#5 dwains
D.I.C Head
Reputation: 0
Posts: 77
Joined: 27-December 08
In is tutorial using VB.Net 2008 was very informitive however in 2008 you dont get the
picturebox as shown I cant seem to figure out how to diplay the image in the datagridview. Any
help would be greatly appreciated. Thanks Dwain Snickles
The following code dosn't work:
Sub LoadPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles LoadPicture.Click
With OpenFileDialog1
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
' Load the specified file into a PictureBox control.
This is where I cant seem to figure out using vb.net 2008?
PicturePictureBox.Image = Image.FromFile(.FileName)
End If
End With
End Sub
Was This Post Helpful? 0
Quote + Reply
#6 steveshergill
New D.I.C Head
Reputation: 0
Posts: 27
Joined: 29-December 08
i am getting an error. When I try to save a record i get the following message.
"UPDATE REQUIRES A VALID DELETECOMMAND WHEN PASSED DATAROW
COLLECTION WITH DELETED ROWS.
IT POINTS TO THIS LINE OF CODE.
CODE:
ME.TABLEADAPTERMANAGER.UPDATEALL(ME.PRINTERS4UDATASET)
Was This Post Helpful? 0
Quote + Reply
#7 marksteele
New D.I.C Head
Reputation: 0
Posts: 1
Joined: 13-January 09
the code works fine for me when I'm trying to look through my database but the add button will
not work. It works until i close VB but it will not actually save the new information to the
database
Was This Post Helpful? 0
Quote + Reply
#8 shankarbtn
New D.I.C Head
Reputation: 0
Posts: 1
Joined: 28-January 09
Quote + Reply
#9 cjscs
New D.I.C Head
Reputation: 0
Posts: 8
Joined: 14-August 09
Great Tutorial! Very informative. I need to look close to see if it answers my problem.
Thanks
Was This Post Helpful? 0
Quote + Reply
#10 sharpy
D.I.C Regular
Reputation: 38
Posts: 396
Joined: 02-June 07
Note: You should get a message at this point asking if you would like to copy a file to your
project click Yes.
Hi all just to say at this point in the tutorial if you click yes a reference of the database will be
added to your project so the project will only access this and not your original database. If you
click no then the project will use the database you originally created.
Quote + Reply
#11 anarcy
New D.I.C Head
Reputation: 0
Posts: 1
Joined: 22-November 09
hey great tutorial one problem how do i open or add the option to open a different database? and
also when i add a new feild it counts backwards from 10 like i click add and the client id starts at
-1 and it goes all weird
email me at fps_anarcy@hotmail.com
p.s disregard last post problem fixed help on this one plz ^
|
Quote + Reply
#12 sharpy
D.I.C Regular
Reputation: 38
Posts: 396
Joined: 02-June 07
Hi Arncy
That is normal when you add a new row. It will show -1 till you save to the database then it will
be given a unique number. If that row is deleted the id number it was assigned will never be used
again as to avoid confusion. So if you have
1
2
3
4
and delete 3
1
2
4
Quote + Reply
#13 Guest_Heeren*
Reputation:
I've added Service-Based Database (MSSQL) to my VB.net application. and connected very well
to it. But, How to deploy that database in a setup project?? OR can client use that database file
"MDF" in different PCs having same software application? like the main server is also having
same software, and after making all those data entries in desktop server pc .. and then copy that
data file to client's laptop which is having same application with server? but, everytime I install
software.. it shows an error.. of naming instance or something.. and database is already exist..
sumthin like that. and when I copy that data file to another PC.. that shows no data in it.
Was This Post Helpful? 0
Quote + Reply
#14 Guest_Guest*
Reputation:
I need some help. I have got the database to run properly however when I publish it it keeps on
referring to an Apps file that it could not find.
Any one out there who could help and give assistance?
Was This Post Helpful? 0
Quote + Reply
#15 Guest_Guest*
Reputation:
Hi All
In this tutorial I will explain how to make a really simple database using a Microsoft Access
database in conjunction with VB.net Express 2008. The way the application is constructed
requires minimal effort as we will utilize the capabilities of the VB.net Express IDE. This
tutorial is aimed at people who are new to programming; I have assumed you have got a basic
Knowledge of Microsoft Access, here goes.
1. Create a folder on you C drive or where ever you like just remember the path, for this example
I used C:\Database. Add three photographs to this file in a JPG format.
2. Open access and create a blank database called DB1 and save it in your database file. Create a
table in design view and add 4 fields
[ClientID] Data type = Auto Number. Set this as the primary Key
[FirstName] Data type = Text
[LastName] Data type = Text
[Picture] Data type = OLE Object
Save the table with the name Clients. Open the table and add this data into the first and last name
fields don’t worry about the picture field.
Peter Jones
David Smith
Jane Doe
3. Open the VB express IDE and select File and New project. Select Windows forms
Application and name it MyaccessDB press OK. You should now have form1 in your IDE
4. The next step is to add our data source to our project. On the left-hand side of the IDE select
the Database explorer window, right click on the Data Connections and select Add connection.
In the Add connection window select Microsoft Access Database File (OLE DB), and then
browse to find our access database and select. Ignore the password and test the connection which
should work. Press OK you should now have our DB1.mdb Database in our Data connections
window.
attachment
Expand the database and then expand the tables folder you should now see the Clients table.
attachment
5. We next have to add a dataset to the project in the solutions explorer. Right click on
myaccessDB and select Add then New Item. Select Dataset and then Add. You should now
have a dataset in the solutions explorer and the Dataset1 tab will be open.
6. We need to add the Clients table to the Dataset, we do this by selecting the Clients table in the
data connections window and drag the table onto the Dataset1 tabbed page.
You should now have a Clients Table Adaptor in the Dataset with an SQL fill query at the
bottom of the table which has been automatically generated. Save the Dataset
attachment
Note: You should get a message at this point asking if you would like to copy a file to your
project click Yes.
attachment
7. We now need to add the Dataset1 to the form. In the main area of the IDE select Form1. In the
solutions explorer open the Data sources window. Expand the Dataset1 to show the clients table,
highlight the clients table and from the drop down menu select details. Expand the clients table
and highlight the Picture field and from the dropdown menu select Picture box. Now highlight
the clients table and drag onto the form1. You will see appear automatically textboxes; labels a
picture box and a binding navigator on the form. You now have a working database. Run the
application and page through the records you have entered. You can now also Add, Delete and
Save records
Although at this point we cannot show a picture which is next.
attachment
8. from the tool box select a button and drag it onto the form, call it Load Picture, double click
the button to open the code editor and paste this code into the buttons sub.
This code is used for the open file dialog which we use to select the picture we want to show
attachment
Run the application and press the load picture Button. Navigate to the database file and select a
picture. Close the dialog box and press the save button on the Navigator strip, the picture will
now be stored in the access database. Repeat this for all the records pictures.
attachment
Note: You may need to expand the picture box and play around with the settings to make the
pictures look right.
And there we have it a fully functional database, if you open up the code editor you will see how
little code is required to achieve what normally takes hundreds of lines of code which I think is
pretty cool and its quick, although there is a lot more code required to make sure the data entered
is correct and indeed all the required fields are filled in. The one thing that is missing is the
ability to search the database using wild cards which I am now going to cover.
9. Drag another button onto form1 and name it Search. Double click the button to enter into the
code editor page and add this line of code.
1 Form2.Show()
10. In the solution explorer add another form (Form2) and then add another dataset (Dataset2).
Keep the dataset2 tap open and drap the client table from the DB1.mdb in the Database Explorer
on to the dataset2. Again you will see the client table adaptor with the automatically create SQL
fill query at the bottom of the table. We will have to edit this query to enable the wild card search
facility.
11. Right click on the table adaptor and select Configure, the table adaptor configuration wizard
will open. You will see the actual SQL Select query. Click Query builder. In the query builder
page scroll down to the lastName record and then scroll across to the input box that says filter,
Place a ? in this filter box then press Ok to close the query builder.
attachment
Keep pressing next then Finish to exit the configuration wizard. The SQL query should now look
like this
Fill,Getdata(LastName)
Note: If you require further filters just add more ? marks in the other fields Filter box.
12. Open the form2 tab and click into the datasource window to show the datasets 1 & 2. Again
expand the Dataset2 and Highlight the Clients table, in the drop down menu select Details. Again
expand the clients table and highlight the picture field and from the drop down menu select
picturebox. Then just highlight clients table and drag onto form2. You should see again
textboxes, labels a picture box and a binding navigator appear on the form with the addition of a
fill tool strip with a LastName textbox and fill button.
attachment
Run the application press the Search and type a second name into the fill tool strip text box and
press fill, you should have 1 record shown.
And there you have it a fully functional database with possibly the smallest amount of code used
which is the main aim of a good programmer. Although it is neccasary to add more code to to do
conditional checks etc. You can also add in combo boxes instead of the Lastname text box you
just need to alter the client Table adaptor to suit see below :-
Me.ClientsTableAdapter.Fill(Me.DataSet2.clients,
1
LastNameToolStripTextBox.Text)
2
3 Me.ClientsTableAdapter.Fill(Me.DataSet2.clients, combobox1.Text)
Just as a footnote I have used an access database however you can add an MS SQL database to
your project by right clicking the project in the solutions explorer and add new item add Service
based database. The database explorer will be populated with the database you have created
where you can add your table and fill it with data. but I will leave you to figure this one out.
Quote + Reply
← Previous Topic
VB.NET Tutorials
Next Topic →
(2 Pages)
1
2
→
General Discussion
Caffeine Lounge
Corner Cubicle
Student Campus
Software Development
Industry News
Introduce Yourself
Nightmare.In.Code
Programming Help
C and C++
VB.NET
Java
C#
Python
PHP
Mobile Development
ASP.NET
.NET Framework
Ruby
Game Development
Assembly
Databases
ColdFusion
VB6
Other Languages
52 Weeks Of Code
Web Development
Web Development
HTML & CSS
JavaScript
Graphic Design
Flash & ActionScript
Blogging
SEO & Advertising
Web Servers & Hosting
Site Check
VB.NET Tutorials
TreeView Drive, Folder, and File Explorer
Sorting Objects by a Property, e.g. Salary
A Simple Custom Control (focussed TextBox)
Using recursion to create a program to backup folders
Idustrial process regulation using a VB.NET PID controller
Exploring DataGridView (ComboBox, Checkbox, Increment, BindingSource)
Exploring a List Without Duplicates
LINQ Group By and Aggregates
Async/Await with Progress(Bar) and Cancellation
Word Template - Fill In, Print and Preview
275 More VB.NET Tutorials...
Reference Sheets
Code Snippets
C Snippets
C++ Snippets
Java Snippets
Visual Basic Snippets
C# Snippets
VB.NET Snippets
ASP.NET Snippets
PHP Snippets
Python Snippets
Ruby Snippets
ColdFusion Snippets
SQL Snippets
Assembly Snippets
Functional Programming Snippets
Perl Snippets
HTML/CSS Snippets
Javascript Snippets
Flash/ActionScript Snippets
ASP Snippets
Linux, Unix, and Bash Snippets
Other Languages Snippets
Regex
DIC Chatroom
Join our IRC Chat