VB .NET Database Questions

VB.Net Cook Book Project

Page 1 of 1

4 Replies - 3750 Views - Last Post: 05 January 2009 - 08:47 AM Rate Topic: -----

#1 bluemoon327  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 10-December 08

VB .NET Database Questions

Posted 11 December 2008 - 11:06 PM

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;


I am new to VB.NET and the above code I can't seem to get it to connect to my database. I am rusty on all my coding abilities and wish to start this project from scratch. Am not looking for anyone to do my homework. Visual Studio 2008 underlines post of the connection string so I know it will error before trying to run the app. I might as well be a beginner when it comes to databases. I know I should be using Dim keywords but not sure what? This is my first attempt with VB.Net and am trying to learn enough to complete a Cook Book database. I will have many more questions later on in this post I'm sure. All I have to go on for an access database is a connection string that alone will not connect. I do not wan't anyone to give me sample code, I can find plenty of sample code for databases on the net. What I wan't is to learn database programming step by step, one line at a time. It is easy to copy and paste code, but I wan't to learn .net coding hands on. My goal is to be able to write any kind of database app from scratch on my own. If you decide to help me with this project please explain your given code where I can understand it.

I am here to learn and am glad to find a site willing to help. In the past I got by, by copying and pasteing code. I am a amature programmer dabbling in different coding languages. I am disabled and I have got to the point that I want to learn from scratch instead of using a template. Here in this forum post I want to learn from scratch how to program a simple database program. There are sample code all over the net for databases, but I came here hoping to learn one code at a time. The code or connection string I posted above I understand most of it, but not ACE.OLEBD.12.0 Please help me to understand what I am writting and help me with what is missing and hopefully explain the code in some detail. If you help me I will help someone else.

In the past I learned what I knew from other peoples sample code. Copying and pasteing was a way of life. Until now there was no one to ask how to do something and what the code means. If you have an itch to teach, then I am here to learn :D Help me write a cook book database and help me know what every line of code means. Once again I don't want anyone doing my homework, so give me homework to do and I will do what you advise.

Brian

I don't see a spell check button here so hope I spelled ok?

Is This A Good Question/Topic? 0
  • +

Replies To: VB .NET Database Questions

#2 jens  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 430
  • Joined: 09-May 08

Re: VB .NET Database Questions

Posted 12 December 2008 - 02:45 AM

Hello and welcome!

I'm not the person to understand and help with your particular problem but I know there are some good tutorials here at D.I.C. Maybe these can help you in your quest for understanding.

Tutor 1
Tutor 2
Tutor 3 OleDB
Tutor 4 SQL

Hope this helps. I'm sure someone will help solve your specific problem.

Regards
/Jens
Was This Post Helpful? 0
  • +
  • -

#3 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: VB .NET Database Questions

Posted 12 December 2008 - 07:51 AM

Quote

The code or connection string I posted above I understand most of it, but not ACE.OLEBD.12.0


Well, to answer that part of the question, ACE.OLEDB.12.0 is the provider that .NET uses to 'talk' with your Access database. That basic setup is how you would define your connection string. Where you go next will determine whether you wish to use standard ADO in a connected/disconnected manner or if you want to use LINQ since you appear to be working with VB 9.0 (2008 release).

If you could provide a little more information in how you want to proceed, I may be able to offer some more assistance.
Was This Post Helpful? 0
  • +
  • -

#4 bluemoon327  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 10-December 08

Re: VB .NET Database Questions

Posted 05 January 2009 - 01:18 AM

View Postnofear217, on 12 Dec, 2008 - 06:51 AM, said:

Quote

The code or connection string I posted above I understand most of it, but not ACE.OLEBD.12.0


Well, to answer that part of the question, ACE.OLEDB.12.0 is the provider that .NET uses to 'talk' with your Access database. That basic setup is how you would define your connection string. Where you go next will determine whether you wish to use standard ADO in a connected/disconnected manner or if you want to use LINQ since you appear to be working with VB 9.0 (2008 release).

If you could provide a little more information in how you want to proceed, I may be able to offer some more assistance.

Sorry it has taken me so long to reply, had PC problems and thought I had this forum set to email me when someone replied. Didn't think anyone was going to help. Thanks for the advice! I have written many database programs with VB 6.0. I uderstand 6.0 better but I never knew everything the code was doing, so I thought a simple cook book database would help me learn more in VB.Net 2008.

I am not trying to get you do do my homework, I hope my first post didn't sound that way. I just want to understand the code better than I do now. In Class1.vb below I found code to connect to an access database:
Option Strict Off
Option Explicit On
Friend Class clsMain
	Public Function OpenConnect() As ADODB.Connection
		Dim com As Object
		com = New ADODB.Command
		Dim dbPath As String
		dbPath = VB6.GetPath & "\" & "cookbook.mdb"
		cnConnection = New ADODB.Connection
		cnConnection = New ADODB.Connection
		With cnConnection
			.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data source ='" & dbPath & "'; Jet OLEDB:database password=123")
		End With
	End Function
End Class


I found the above code online and tested it, it works but will it work with the new MS Access .mdbx database? I do not fully understand this code. Is this code good to use? It works with mdb files but will it work with mdbx files? I want to learn the coding skills. Why does the above code use VB6.GetPath? If this is good code can someone walk me through it. I really want to use code that will work with the latest MS Access databases.

This is the way I found the code, does it have to be in a class.vb file? The fewer files I work with the better I understand what's going on. Thanks for helping... I am just trying to learn.
Was This Post Helpful? 0
  • +
  • -

#5 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: VB .NET Database Questions

Posted 05 January 2009 - 08:47 AM

Quote

Why does the above code use VB6.GetPath?


My guess would be that there is another class that contains the location of your stored mdb files and then just concatenates it with your file name. On a side note, the new Access database files are of format .accdb. Also, I'm not exactly sure why they are doing what they do with the command or connection strings. It looks like again ADODB is another class that contains some public functions/properties that are being set. I don't know why they are dimensioning the command as an object when they just box it up to what appears to be an oledb command.

A sample of some code that gets a count from Table1 in a MS Access 2007 database:

            Dim conn As New OleDb.OleDbConnection
            conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb"
            Dim SelSta As String = "Select Count(ID) from Table1"
            Dim cmd As New OleDb.OleDbCommand
            cmd.CommandText = SelSta
            cmd.CommandType = CommandType.Text
            cmd.Connection = conn

            cmd.Connection.Open()
            NumRec = cmd.ExecuteScalar
            cmd.Connection.Close()

            If NumRec = 0 Then
                MsgBox("No items returned")
            Else
                MsgBox("There's stuff there")
            End If


This post has been edited by nofear217: 05 January 2009 - 08:48 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1