linking database to my VB project

casualrich

Member
Joined
Dec 17, 2008
Messages
12
Programming Experience
1-3
Hi Im new hear I have been using VB for about 3 years now, got this assignment at uni and I ave done the first bit!!!

but its the second but which Im unsure about Im trying to link a database to my project and get information to show on my form using a complex query

here is my code where am I going wrong

PLEASE PLEASE HELP ME!!

VB.NET:
 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()

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'.
PLEASE HELP ME!!
 
Is your database in the debug folder?

I would take a look at this series: Link to see how Visual Studio can do all of the donkey work for you.

The series uses SQL Server as the provider and it appears you're using Access. You'll need to change the provider to OleDB for MS Access when setting up the connection; otherwise everything else is the same.
 
yh the file is now in the debug folder this is the message im now getting
this is the error message Im now getting when the run the programme
The Microsoft Jet database engine cannot find the input table or query 'JobNo'. Make sure it exists and that its name is spelled correctly.

i dont know wot to do for the best!!!

i want to put the data into a datagrid but how to i declare this in my coding?
 
Is your table named 'Engineer No' with the space?

VB.NET:
Dim sqlStr As String = "Select * FROM Engineer No"

If so you'll need to add brackets around the table name so it looks for the whole table name rather than thinking you're aliasing a table called Engineer.

VB.NET:
Dim sqlStr As String = "Select * FROM [Engineer No]"
 

Latest posts

Back
Top