attaching a database to VB project

uni project work need help !

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 2594 Views - Last Post: 17 December 2008 - 09:35 AM Rate Topic: -----

#1 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

attaching a database to VB project

Post icon  Posted 15 December 2008 - 10:01 AM

hi im trying to acctach a database to my VB programme but when i run the programme it dosent seemt to like the code can anybody help please!!

i need to do this by writing my own code and NOT with the VB wizard please please help me!
Format of the initialization string does not conform to specification starting at index 0.

 Private Sub butquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butquery.Click
		Dim connStr As Integer
		Dim dt As New DataTable
		Dim commStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
								"Data Source= EngineerJobs.MDB"
		Dim sqlStr As String = "Select * FROM Engineer No"
		Dim DataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
		DataAdapter.Fill(dt)
		DataAdapter.Dispose() 


Is This A Good Question/Topic? 0
  • +

Replies To: attaching a database to VB project

#2 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: attaching a database to VB project

Posted 15 December 2008 - 10:12 AM

Looks like you are working with some type of Access DB. What kind of an error message are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 15 December 2008 - 10:27 AM

View Postnofear217, on 15 Dec, 2008 - 09:12 AM, said:

Looks like you are working with some type of Access DB. What kind of an error message are you getting?


this is the error message that im getting!
Format of the initialization string does not conform to specification starting at index 0.
Was This Post Helpful? 0
  • +
  • -

#4 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: attaching a database to VB project

Posted 15 December 2008 - 11:18 AM

In your code, you declared connStr as an integer but never initialized it, then you initialized commStr as your connection string. However, when you declared your data adapter, you used connStr (the integer) rather than commStr as the connection string parameter. If that is your code exactly as you posted it, that is likely your problem.

This post has been edited by nofear217: 15 December 2008 - 11:19 AM

Was This Post Helpful? 0
  • +
  • -

#5 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 16 December 2008 - 02:09 AM

View Postnofear217, on 15 Dec, 2008 - 10:18 AM, said:

In your code, you declared connStr as an integer but never initialized it, then you initialized commStr as your connection string. However, when you declared your data adapter, you used connStr (the integer) rather than commStr as the connection string parameter. If that is your code exactly as you posted it, that is likely your problem.


right ok can you please show me this in a piece of code please!
Was This Post Helpful? 0
  • +
  • -

#6 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: attaching a database to VB project

Posted 16 December 2008 - 04:07 AM

I think he means that you added the wrong variable to the data adapter, it needs 2 strings and you have given it a string and an integer, try the following.

 Private Sub butquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butquery.Click
		Dim connStr As Integer
		Dim dt As New DataTable
		Dim commStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
								"Data Source= EngineerJobs.MDB"
		Dim sqlStr As String = "Select * FROM Engineer No"
		Dim DataAdapter As New OleDb.OleDbDataAdapter(sqlStr, commStr)
		DataAdapter.Fill(dt)
		DataAdapter.Dispose()


This post has been edited by nightscream: 16 December 2008 - 04:09 AM

Was This Post Helpful? 0
  • +
  • -

#7 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 16 December 2008 - 05:21 AM

View Postnightscream, on 16 Dec, 2008 - 03:07 AM, said:

I think he means that you added the wrong variable to the data adapter, it needs 2 strings and you have given it a string and an integer, try the following.

 Private Sub butquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butquery.Click
		Dim connStr As Integer
		Dim dt As New DataTable
		Dim commStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
								"Data Source= EngineerJobs.MDB"
		Dim sqlStr As String = "Select * FROM Engineer No"
		Dim DataAdapter As New OleDb.OleDbDataAdapter(sqlStr, commStr)
		DataAdapter.Fill(dt)
		DataAdapter.Dispose()


thats brill thanks just one more quick prob!!

i now get this when i run the programme! Could not find file 'F:\Richard's Uni Sept 08-9\Software Development\SU computer repairs Richard Hemmings Assignment\RHemmings Assignment\RHemmings Assignment\RHemmings Assignment\bin\Debug\EngineerJobs.MDB'.
Was This Post Helpful? 0
  • +
  • -

#8 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 16 December 2008 - 08:49 AM

any1 please help me?????
Was This Post Helpful? 0
  • +
  • -

#9 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 17 December 2008 - 01:40 AM

View Postrich_hemmings, on 16 Dec, 2008 - 04:21 AM, said:

View Postnightscream, on 16 Dec, 2008 - 03:07 AM, said:

I think he means that you added the wrong variable to the data adapter, it needs 2 strings and you have given it a string and an integer, try the following.

 Private Sub butquery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butquery.Click
		Dim connStr As Integer
		Dim dt As New DataTable
		Dim commStr As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
								"Data Source= EngineerJobs.MDB"
		Dim sqlStr As String = "Select * FROM Engineer No"
		Dim DataAdapter As New OleDb.OleDbDataAdapter(sqlStr, commStr)
		DataAdapter.Fill(dt)
		DataAdapter.Dispose()


thats brill thanks just one more quick prob!!

i now get this when i run the programme! Could not find file 'F:\Richard's Uni Sept 08-9\Software Development\SU computer repairs Richard Hemmings Assignment\RHemmings Assignment\RHemmings Assignment\RHemmings Assignment\bin\Debug\EngineerJobs.MDB'.

[b]please anybody got any ideas please[s][size=7]
Was This Post Helpful? 0
  • +
  • -

#10 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,923
  • Joined: 18-September 06

Re: attaching a database to VB project

Posted 17 December 2008 - 03:30 AM

Move a copy of your database into the bin\Debug folder. This is the folder it uses when testing your app when you run it in VB.
Was This Post Helpful? 0
  • +
  • -

#11 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 17 December 2008 - 03:46 AM

View PostBort, on 17 Dec, 2008 - 02:30 AM, said:

Move a copy of your database into the bin\Debug folder. This is the folder it uses when testing your app when you run it in VB.


hi thanks for that!

i now get this when i run the programme"

DataAdapter.Fill(dt) 
Syntax error in FROM clause.

why cant t be simple!

please help me!!
Was This Post Helpful? 0
  • +
  • -

#12 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,923
  • Joined: 18-September 06

Re: attaching a database to VB project

Posted 17 December 2008 - 03:57 AM

This is the line that it is having problems with:

Dim sqlStr As String = "Select * FROM Engineer No"



I'm guessing it can't find the "Engineer No" table. Is Engineer No a table, or a field in a table? If it is a field, then you will probably want that line to read:

Dim sqlStr As String = "Select Engineer No FROM TableName"



Either that, or I do vaguely recall reading something about the table names having spaces in them. Try renaming the table 'EngineerNo'.
Was This Post Helpful? 0
  • +
  • -

#13 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 17 December 2008 - 04:06 AM

View PostBort, on 17 Dec, 2008 - 02:57 AM, said:

This is the line that it is having problems with:

Dim sqlStr As String = "Select * FROM Engineer No"



I'm guessing it can't find the "Engineer No" table. Is Engineer No a table, or a field in a table? If it is a field, then you will probably want that line to read:

Dim sqlStr As String = "Select Engineer No FROM TableName"



Either that, or I do vaguely recall reading something about the table names having spaces in them. Try renaming the table 'EngineerNo'.


ok thats is brilliant thank you I will have a look at this now!!

also when its working properly will it just show on the form when its running or do i need to but anything onto the form?
Was This Post Helpful? 0
  • +
  • -

#14 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,923
  • Joined: 18-September 06

Re: attaching a database to VB project

Posted 17 December 2008 - 04:15 AM

From the Data Sources window, drag the table you want displayed onto the form. there are a number of options here though, which you may want to play with and see what does what. It is possible to have the data from the table displayed in a table or a selection of textboxes, etc.

Have a play around with the Data Sources window to see what you can do.

Good luck :)

Bort
Was This Post Helpful? 0
  • +
  • -

#15 rich_hemmings  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 05-November 08

Re: attaching a database to VB project

Posted 17 December 2008 - 04:18 AM

View PostBort, on 17 Dec, 2008 - 03:15 AM, said:

From the Data Sources window, drag the table you want displayed onto the form. there are a number of options here though, which you may want to play with and see what does what. It is possible to have the data from the table displayed in a table or a selection of textboxes, etc.

Have a play around with the Data Sources window to see what you can do.

Good luck :)

Bort


ok I will do!! er but wotn that mean if I use the data source window Vb will do the code for me??

aslo this is what Im getting now sorry to be such a pain!
The Microsoft Jet database engine cannot find the input table or query 'JobNo'. Make sure it exists and that its name is spelled correctly.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2