Search This Blog

Sunday, May 1, 2011

How to connect vb.net winform app to MS Access 2003

Hello my dear viewer in this article I'm going to show to connect your Visual Basic.net Windows Application to MS Access 2003.

Now to get things started open your ms access 2003 and create a database name it "sample", if your  version is 2007 or onwards don't forget to save as the database in 2003 format. To check if your database is in 2003 format the extension file should be ".mdb".

  • After we create the database, open your visual studio and create a project. To create the project go to "file>new>project" choose visual basic as the language and the type should be Windows Form Application.


  • For the name of the project type "sample" and for the location and solution leave it to its default and press OK. 



  • Now to start the coding double click on in the form1 and this should be in your screen now.

  • First part of the code is we need to declare our import, click your mouse cursor before the Public Class Form1 and hit enter. After that type “Imports  System.Data.OleDb ". 
  • Now that we declare our import next would be to declare is our oledbconnection. The purpose of oledbconnection is it acts as a switch to open or close the connection to our database. Click your mouse cursor below the Public Class Form1 then type "Dim con As New OleDbConnection".
  • After declaring our import and oledbconnection we need now to specify our connection string and open our connection to check if it really connects to our database. Click inside between the private sub and end sub then type the following line of code. 
con.ConnectionString = "Provider= microsoft.jet.oledb.4.0;" + _
"data source=c:\sample.mdb"
con.Open()
MessageBox.Show("Connected")
con.Close()


  • If you notice in our connection string the provider we need to use since we are using MS Access 2003 is microsoft.jet.oledb.4.0 and for the data source is where our database is located. In this example I choose to place my database into my drive c so that it will be easier for me to locate the database. For further connection you can check this link connection strings.

  • Below is the picture how the code should look like now.
      
    Thanks for reading and hope this article help you. If you think this article is helpful kindly share or refer to other thanks.

    Saturday, April 30, 2011

    Hello viewer

    Sharing knowledge is not about giving people something, or getting something from them. That is only valid for information sharing. Sharing knowledge occurs when people are genuinely interested in helping one another develop new capacities for action; it is about creating learning processes.






    A very inspiring quote isn't? By the way I'm Jordan N. Capoquian currently a 4th year student in STI College Las Pinas and taking B.S. in Information Technology. Sharing knowledge that's I learn that’s the main reason for me to create this blog. To give some preview on what you might perceive, this blog aim about computer programming. Yup it’s about computer programming, my passion for programming start when I'm in high school. One day my cousin invite me to play some computer games and I was very happy that time because that's the first time I had played computer games. Because of the happiness I felt that time, a big question came up in my mind that is “How do they create this computer games I am playing?” Few days of research and the answer came up and that is computer programming and after high school graduation I decided to take a course related to computer programming. Now here I am 1 year before I graduate starting to write this blog help others who have passion in computer programming also.