[quoted text, click to view] On Tue, 06 Dec 2005 20:38:29 GMT, Mr. B <User@NoWhere.com> wrote:
¤ VB.net 2003; MS Access db; Netframe 1.1
¤
¤ I wrote an Windows app for my last place of employment that opened and
¤ modified a couple of MS Access db files. I did most of my programming at home
¤ on Drive "C". And I used the Drag/Drop Data Items to create the Connection,
¤ DataSet and DataAdapters.
¤
¤ The Access files were located on drives "P" and "S" at work, so I had VB.net
¤ installed on my work PC so I could change the drives in the Connection Icons.
¤
¤ Now I no longer work at that place and they want me to make some changes. Of
¤ course I can't as I don't have a drive P or S on my system. So I'm attempting
¤ to get rid of the Data Icons and do the connection, Data set and adapters with
¤ Code. And of course I'm getting all kinds of errors.
¤
¤ So I'm doing a Test app to find/fix my items. Right off the bat I can't even
¤ establish a proper connection to a DB. The following is that code I'm using.
¤
¤ I get an ERROR at the FILL line (unhandled exception where "Value cannot be
¤ null". But the access file opens just fine if I use the DATA Icons.
¤
¤ And... If I change the Fill line to:
¤ daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
¤ ... the error then says "The ConnectionString property has not been
¤ initialized".
¤
¤ ************** CODE ***********************************************
¤ Imports System.IO
¤ Imports System.Data.OleDb
¤
¤ ' Connection String1 to SHENTSdata.mdb
¤ Dim connString1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
¤ Source=TSdbPath & SHENTSdata.mdb"
¤
¤ Dim OleDbConnection1 As OleDbConnection = New OleDbConnection
¤
¤ ' Data Adapter 1
¤ Dim strSelect1 As String
¤ strSelect1 = "SELECT Bill_Code, Dispersmts, Fri_Hrs, Job_Descrn,
¤ Job_Number, Mileage," & _
¤ "Mon_Hrs, Period_End_Date, PO_Order, Sat_Hrs, Sun_Hrs,
¤ Thr_Hrs, Tue_Hrs," & _
¤ "Wed_Hrs, Work_Descrn FROM SHENHrsTable"
¤ Dim daShenData As New OleDbDataAdapter(strSelect1, OleDbConnection1)
¤
¤ ' Dataset 1
¤ Dim dsShenData As New DataSet
¤
¤ ' Fill Dataset 1
¤ daShenData.Fill(dsShenData.Tables("SHENHrsTable"))
¤ '''daShenData.FillSchema(dsShenData, SchemaType.Source, "SHENHrsTable")
¤ ********************************************************************
¤
¤ QUESTION #1:
¤ How do I fix the No Null value issue (why is it doing this anyways)?
¤
¤ QUESTION #2:
¤ When I get this to work, where is the best place to place this code in my
¤ application? In the Form Load? Between Form Load and "Windows Form Designer
¤ generated code"? In a Module? In a Public Sub? This is because I open and
¤ edit the Data bases elsewhere so I don't really know how to make it more
¤ 'globally' available.
¤
¤ QUESTION #3:
¤ (a bit off topic) Or should I forget the whole thing... stick with my DATA
¤ Icons... and use the SUBST command to create Virtual Drives and Fake it that
¤ way?
¤
Where is the line of code where you Open the OleDbConnection1 object?
Typically you open and close connections as you need them instead of maintaining persistent
connections. In this instance you probably want to add a Sub or Function to your Form and call it
from your Form Load event.
You can use the data connection objects (DATA Icons you called them) you created with the wizard,
but you need to change the connection string property at runtime (either in your Sub Main or Form
Load event).
Paul
~~~~