landers wrote:
Is this a web app or a windows app?
[quoted text clipped - 7 lines] database *.mdb file both locally on my C:\ drive as well as on a network
share drive. I get the same exception error message either way.
Hi,
Please post your code.
Have you tried opening the mdb file directly?
Landers
Here is the code. It is very simple. A form with a data grid to load an
Access table. One button to load the data grid and another to update the
Access database. There is no security on the database as right now this is
just a test to learn how to establish database connectivity and associating
windows app controls with table fields via data binding.
Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeCompo nent()
'Add any initialization after the InitializeCompo nent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OleDbSelectComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbInsertComm and1 As System.Data.Ole Db.OleDbCommand
Friend WithEvents OleDbConnection 1 As System.Data.Ole Db.OleDbConnect ion
Friend WithEvents OleDbDataAdapte r1 As System.Data.Ole Db.OleDbDataAda pter
Friend WithEvents DataGrid1 As System.Windows. Forms.DataGrid
Friend WithEvents DataSet11 As TestDBApp.DataS et1
Friend WithEvents Button1 As System.Windows. Forms.Button
Friend WithEvents Button2 As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.OleDbSelectC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.OleDbInsertC ommand1 = New System.Data.Ole Db.OleDbCommand
Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
Me.OleDbDataAda pter1 = New System.Data.Ole Db.OleDbDataAda pter
Me.DataGrid1 = New System.Windows. Forms.DataGrid
Me.DataSet11 = New TestDBApp.DataS et1
Me.Button1 = New System.Windows. Forms.Button
Me.Button2 = New System.Windows. Forms.Button
CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).
BeginInit()
CType(Me.DataSe t11, System.Componen tModel.ISupport Initialize).
BeginInit()
Me.SuspendLayou t()
'
'OleDbSelectCom mand1
'
Me.OleDbSelectC ommand1.Command Text = "SELECT Grade, Name FROM
Students"
Me.OleDbSelectC ommand1.Connect ion = Me.OleDbConnect ion1
'
'OleDbInsertCom mand1
'
Me.OleDbInsertC ommand1.Command Text = "INSERT INTO Students(Grade,
Name) VALUES (?, ?)"
Me.OleDbInsertC ommand1.Connect ion = Me.OleDbConnect ion1
Me.OleDbInsertC ommand1.Paramet ers.Add(New System.Data.Ole Db.
OleDbParameter( "Grade", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Grade"))
Me.OleDbInsertC ommand1.Paramet ers.Add(New System.Data.Ole Db.
OleDbParameter( "Name", System.Data.Ole Db.OleDbType.Va rWChar, 50, "Name"))
'
'OleDbConnectio n1
'
Me.OleDbConnect ion1.Connection String = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""H:\Vis ual Basic .NET\Students.m db"";Jet
OLEDB:Engine T" & _
"ype=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:System
database=;Jet OLEDB:SF" & _
"P=False;persis t security info=False;Exte nded Properties=;Mod e=Share
Deny None;Je" & _
"t OLEDB:Encrypt Database=False; Jet OLEDB:Create System
Database=False; Jet OLEDB:" & _
"Don't Copy Locale on Compact=False;J et OLEDB:Compact Without Replica
Repair=Fals" & _
"e;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbDataAdapt er1
'
Me.OleDbDataAda pter1.InsertCom mand = Me.OleDbInsertC ommand1
Me.OleDbDataAda pter1.SelectCom mand = Me.OleDbSelectC ommand1
Me.OleDbDataAda pter1.TableMapp ings.AddRange(N ew System.Data.Com mon.
DataTableMappin g() {New System.Data.Com mon.DataTableMa pping("Table",
"Students", New System.Data.Com mon.DataColumnM apping() {New System.Data.
Common.DataColu mnMapping("Grad e", "Grade"), New System.Data.Com mon.
DataColumnMappi ng("Name", "Name")})})
'
'DataGrid1
'
Me.DataGrid1.Da taMember = ""
Me.DataGrid1.Da taSource = Me.DataSet11.St udents
Me.DataGrid1.He aderForeColor = System.Drawing. SystemColors.
ControlText
Me.DataGrid1.Lo cation = New System.Drawing. Point(64, 48)
Me.DataGrid1.Na me = "DataGrid1"
Me.DataGrid1.Si ze = New System.Drawing. Size(272, 232)
Me.DataGrid1.Ta bIndex = 0
'
'DataSet11
'
Me.DataSet11.Da taSetName = "DataSet1"
Me.DataSet11.Lo cale = New System.Globaliz ation.CultureIn fo("en-US")
'
'Button1
'
Me.Button1.Loca tion = New System.Drawing. Point(72, 336)
Me.Button1.Name = "Button1"
Me.Button1.TabI ndex = 1
Me.Button1.Text = "Load Data"
'
'Button2
'
Me.Button2.Loca tion = New System.Drawing. Point(256, 336)
Me.Button2.Name = "Button2"
Me.Button2.TabI ndex = 2
Me.Button2.Text = "Save Data"
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(408, 406)
Me.Controls.Add (Me.Button2)
Me.Controls.Add (Me.Button1)
Me.Controls.Add (Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGr id1, System.Componen tModel.ISupport Initialize).End Init
()
CType(Me.DataSe t11, System.Componen tModel.ISupport Initialize).End Init
()
Me.ResumeLayout (False)
End Sub
#End Region
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
DataSet11.Clear ()
OleDbDataAdapte r1.Fill(DataSet 11)
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
OleDbDataAdapte r1.Update(DataS et11)
End Sub
End Class
--
Message posted via
http://www.dotnetmonster.com