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.
InitializeComponent()
'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'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 OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents DataSet11 As TestDBApp.DataSet1
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DataSet11 = New TestDBApp.DataSet1
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).
BeginInit()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).
BeginInit()
Me.SuspendLayout()
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT Grade, Name FROM
Students"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO Students(Grade,
Name) VALUES (?, ?)"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.
OleDbParameter("Grade", System.Data.OleDb.OleDbType.VarWChar, 50, "Grade"))
Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.
OleDbParameter("Name", System.Data.OleDb.OleDbType.VarWChar, 50, "Name"))
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""H:\Visual Basic .NET\Students.mdb"";Jet
OLEDB:Engine T" & _
"ype=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Je t OLEDB:System
database=;Jet OLEDB:SF" & _
"P=False;persist security info=False;Extended Properties=;Mode=Share
Deny None;Je" & _
"t OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet OLEDB:" & _
"Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica
Repair=Fals" & _
"e;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.
DataTableMapping() {New System.Data.Common.DataTableMapping("Table",
"Students", New System.Data.Common.DataColumnMapping() {New System.Data.
Common.DataColumnMapping("Grade", "Grade"), New System.Data.Common.
DataColumnMapping("Name", "Name")})})
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.DataSource = Me.DataSet11.Students
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.
ControlText
Me.DataGrid1.Location = New System.Drawing.Point(64, 48)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(272, 232)
Me.DataGrid1.TabIndex = 0
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 336)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Load Data"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(256, 336)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Save Data"
'
'Form1
'
Me.AutoScaleBaseSize = 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.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit
()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit
()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
DataSet11.Clear()
OleDbDataAdapter1.Fill(DataSet11)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
OleDbDataAdapter1.Update(DataSet11)
End Sub
End Class
--
Message posted via
http://www.dotnetmonster.com