M
Mike
Hi All;
Learning ADO.Net and did a simple form to see how everything works.
Data is displayed but changes are not updated.
Here is the code:
Imports System.Data.OleDb
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 RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Friend WithEvents ExplanatoryDataSet1 As
CSIComboBox.ExplanatoryDataSet
Friend WithEvents OleDbDataAdapter2 As
System.Data.OleDb.OleDbDataAdapter
Friend WithEvents ExpCodesDataSet1 As CSIComboBox.ExpCodesDataSet1
Friend WithEvents OleDbSelectCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents save As System.Windows.Forms.Button
Friend WithEvents Delete As System.Windows.Forms.Button
Friend WithEvents OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand1 As
System.Data.OleDb.OleDbCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.ExplanatoryDataSet1 = New CSIComboBox.ExplanatoryDataSet
Me.ExpCodesDataSet1 = New CSIComboBox.ExpCodesDataSet1
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDataAdapter2 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand2 = New System.Data.OleDb.OleDbCommand
Me.save = New System.Windows.Forms.Button
Me.Delete = New System.Windows.Forms.Button
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
CType(Me.ExplanatoryDataSet1,
System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.ExpCodesDataSet1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_desc"))
Me.RichTextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Tag", Me.ExpCodesDataSet1,
"msp_explanatory_codes.exp_id"))
Me.RichTextBox1.Location = New System.Drawing.Point(40, 88)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(224, 36)
Me.RichTextBox1.TabIndex = 2
Me.RichTextBox1.Text = "RichTextBox1"
'
'ExplanatoryDataSet1
'
Me.ExplanatoryDataSet1.DataSetName = "ExplanatoryDataSet"
Me.ExplanatoryDataSet1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'ExpCodesDataSet1
'
Me.ExpCodesDataSet1.DataSetName = "ExpCodesDataSet1"
Me.ExpCodesDataSet1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'ComboBox1
'
Me.ComboBox1.DataSource =
Me.ExpCodesDataSet1.msp_explanatory_codes
Me.ComboBox1.DisplayMember = "exp_id"
Me.ComboBox1.Location = New System.Drawing.Point(40, 20)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(164, 21)
Me.ComboBox1.TabIndex = 3
Me.ComboBox1.ValueMember = "exp_id"
'
'TextBox1
'
Me.TextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_solution"))
Me.TextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Tag", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_solution"))
Me.TextBox1.Location = New System.Drawing.Point(44, 156)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(220, 80)
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = "TextBox1"
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDBatabase L" & _
"ocking Mode=0;Data
Source=""C:\test.db\great_big_test_database.mdb"";Jet OLEDB:Eng" & _
"ine Type=4;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Jet OLE" & _
"DB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny No" & _
"ne;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet O" & _
"LEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact
Without Replica Repair" & _
"=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1
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", "msp_explanatory_codes",
New System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("exp_desc", "exp_desc"), New
System.Data.Common.DataColumnMapping("exp_id", "exp_id"), New
System.Data.Common.DataColumnMapping("exp_solution",
"exp_solution")})})
Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1
'
'OleDbDataAdapter2
'
Me.OleDbDataAdapter2.DeleteCommand = Me.OleDbDeleteCommand2
Me.OleDbDataAdapter2.InsertCommand = Me.OleDbInsertCommand2
Me.OleDbDataAdapter2.SelectCommand = Me.OleDbSelectCommand2
Me.OleDbDataAdapter2.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "msp_explanatory_codes",
New System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("exp_id", "exp_id")})})
Me.OleDbDataAdapter2.UpdateCommand = Me.OleDbUpdateCommand2
'
'OleDbDeleteCommand2
'
Me.OleDbDeleteCommand2.CommandText = "DELETE FROM
msp_explanatory_codes WHERE (exp_id = ?)"
Me.OleDbDeleteCommand2.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbInsertCommand2
'
Me.OleDbInsertCommand2.CommandText = "INSERT INTO
msp_explanatory_codes(exp_id) VALUES (?)"
Me.OleDbInsertCommand2.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
'
'OleDbSelectCommand2
'
Me.OleDbSelectCommand2.CommandText = "SELECT exp_id FROM
msp_explanatory_codes"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection1
'
'OleDbUpdateCommand2
'
Me.OleDbUpdateCommand2.CommandText = "UPDATE
msp_explanatory_codes SET exp_id = ? WHERE (exp_id = ?)"
Me.OleDbUpdateCommand2.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
'
'save
'
Me.save.Location = New System.Drawing.Point(28, 256)
Me.save.Name = "save"
Me.save.Size = New System.Drawing.Size(64, 24)
Me.save.TabIndex = 5
Me.save.Text = "Save"
'
'Delete
'
Me.Delete.Location = New System.Drawing.Point(168, 256)
Me.Delete.Name = "Delete"
Me.Delete.Size = New System.Drawing.Size(68, 24)
Me.Delete.TabIndex = 6
Me.Delete.Text = "Delete"
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT exp_desc, exp_id,
exp_solution FROM msp_explanatory_codes WHERE (exp_id = " & _
"?)"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
Me.OleDbSelectCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO
msp_explanatory_codes(exp_desc, exp_id, exp_solution) VALUES (?, ?, ?"
& _
")"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180, "exp_desc"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240, "exp_solution"))
'
'OleDbUpdateCommand1
'
Me.OleDbUpdateCommand1.CommandText = "UPDATE
msp_explanatory_codes SET exp_desc = ?, exp_id = ?, exp_solution = ?
WHERE" & _
" (exp_id = ?) AND (exp_desc = ?) AND (exp_solution = ? OR ?
IS NULL AND exp_solu" & _
"tion IS NULL)"
Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180, "exp_desc"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240, "exp_solution"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_desc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution1",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbDeleteCommand1
'
Me.OleDbDeleteCommand1.CommandText = "DELETE FROM
msp_explanatory_codes WHERE (exp_id = ?) AND (exp_desc = ?) AND (exp_"
& _
"solution = ? OR ? IS NULL AND exp_solution IS NULL)"
Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_desc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution1",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 294)
Me.Controls.Add(Me.Delete)
Me.Controls.Add(Me.save)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.ExplanatoryDataSet1,
System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.ExpCodesDataSet1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ExpCodesDataSet1.Clear()
Me.OleDbDataAdapter2.Fill(Me.ExpCodesDataSet1)
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.TextChanged
Me.OleDbDataAdapter1.SelectCommand.Parameters.Item(0).Value =
Me.ComboBox1.Text
Me.ExplanatoryDataSet1.Clear()
Me.OleDbDataAdapter1.Fill(Me.ExplanatoryDataSet1)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.OleDbDataAdapter1.SelectCommand.Parameters.Item(0).Value =
Me.ComboBox1.SelectedValue
Me.ExplanatoryDataSet1.Clear()
Me.OleDbDataAdapter1.Fill(Me.ExplanatoryDataSet1)
End Sub
Private Sub save_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles save.Click
MsgBox(Me.ExplanatoryDataSet1.HasChanges.ToString)
result = Me.OleDbDataAdapter1.Update(Me.ExplanatoryDataSet1)
MsgBox(result.ToString)
End Sub
End Class
Thanks!
Learning ADO.Net and did a simple form to see how everything works.
Data is displayed but changes are not updated.
Here is the code:
Imports System.Data.OleDb
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 RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents OleDbConnection1 As
System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbDataAdapter1 As
System.Data.OleDb.OleDbDataAdapter
Friend WithEvents ExplanatoryDataSet1 As
CSIComboBox.ExplanatoryDataSet
Friend WithEvents OleDbDataAdapter2 As
System.Data.OleDb.OleDbDataAdapter
Friend WithEvents ExpCodesDataSet1 As CSIComboBox.ExpCodesDataSet1
Friend WithEvents OleDbSelectCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand2 As
System.Data.OleDb.OleDbCommand
Friend WithEvents save As System.Windows.Forms.Button
Friend WithEvents Delete As System.Windows.Forms.Button
Friend WithEvents OleDbSelectCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbInsertCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbUpdateCommand1 As
System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbDeleteCommand1 As
System.Data.OleDb.OleDbCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.ExplanatoryDataSet1 = New CSIComboBox.ExplanatoryDataSet
Me.ExpCodesDataSet1 = New CSIComboBox.ExpCodesDataSet1
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDataAdapter2 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbDeleteCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand2 = New System.Data.OleDb.OleDbCommand
Me.save = New System.Windows.Forms.Button
Me.Delete = New System.Windows.Forms.Button
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbDeleteCommand1 = New System.Data.OleDb.OleDbCommand
CType(Me.ExplanatoryDataSet1,
System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.ExpCodesDataSet1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_desc"))
Me.RichTextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Tag", Me.ExpCodesDataSet1,
"msp_explanatory_codes.exp_id"))
Me.RichTextBox1.Location = New System.Drawing.Point(40, 88)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(224, 36)
Me.RichTextBox1.TabIndex = 2
Me.RichTextBox1.Text = "RichTextBox1"
'
'ExplanatoryDataSet1
'
Me.ExplanatoryDataSet1.DataSetName = "ExplanatoryDataSet"
Me.ExplanatoryDataSet1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'ExpCodesDataSet1
'
Me.ExpCodesDataSet1.DataSetName = "ExpCodesDataSet1"
Me.ExpCodesDataSet1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'ComboBox1
'
Me.ComboBox1.DataSource =
Me.ExpCodesDataSet1.msp_explanatory_codes
Me.ComboBox1.DisplayMember = "exp_id"
Me.ComboBox1.Location = New System.Drawing.Point(40, 20)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(164, 21)
Me.ComboBox1.TabIndex = 3
Me.ComboBox1.ValueMember = "exp_id"
'
'TextBox1
'
Me.TextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Text", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_solution"))
Me.TextBox1.DataBindings.Add(New
System.Windows.Forms.Binding("Tag", Me.ExplanatoryDataSet1,
"msp_explanatory_codes.exp_solution"))
Me.TextBox1.Location = New System.Drawing.Point(44, 156)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(220, 80)
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = "TextBox1"
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global
Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDBatabase L" & _
"ocking Mode=0;Data
Source=""C:\test.db\great_big_test_database.mdb"";Jet OLEDB:Eng" & _
"ine Type=4;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet
OLEDB:System database=;Jet OLE" & _
"DB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny No" & _
"ne;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet O" & _
"LEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact
Without Replica Repair" & _
"=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.DeleteCommand = Me.OleDbDeleteCommand1
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", "msp_explanatory_codes",
New System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("exp_desc", "exp_desc"), New
System.Data.Common.DataColumnMapping("exp_id", "exp_id"), New
System.Data.Common.DataColumnMapping("exp_solution",
"exp_solution")})})
Me.OleDbDataAdapter1.UpdateCommand = Me.OleDbUpdateCommand1
'
'OleDbDataAdapter2
'
Me.OleDbDataAdapter2.DeleteCommand = Me.OleDbDeleteCommand2
Me.OleDbDataAdapter2.InsertCommand = Me.OleDbInsertCommand2
Me.OleDbDataAdapter2.SelectCommand = Me.OleDbSelectCommand2
Me.OleDbDataAdapter2.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "msp_explanatory_codes",
New System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("exp_id", "exp_id")})})
Me.OleDbDataAdapter2.UpdateCommand = Me.OleDbUpdateCommand2
'
'OleDbDeleteCommand2
'
Me.OleDbDeleteCommand2.CommandText = "DELETE FROM
msp_explanatory_codes WHERE (exp_id = ?)"
Me.OleDbDeleteCommand2.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbInsertCommand2
'
Me.OleDbInsertCommand2.CommandText = "INSERT INTO
msp_explanatory_codes(exp_id) VALUES (?)"
Me.OleDbInsertCommand2.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
'
'OleDbSelectCommand2
'
Me.OleDbSelectCommand2.CommandText = "SELECT exp_id FROM
msp_explanatory_codes"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection1
'
'OleDbUpdateCommand2
'
Me.OleDbUpdateCommand2.CommandText = "UPDATE
msp_explanatory_codes SET exp_id = ? WHERE (exp_id = ?)"
Me.OleDbUpdateCommand2.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbUpdateCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
'
'save
'
Me.save.Location = New System.Drawing.Point(28, 256)
Me.save.Name = "save"
Me.save.Size = New System.Drawing.Size(64, 24)
Me.save.TabIndex = 5
Me.save.Text = "Save"
'
'Delete
'
Me.Delete.Location = New System.Drawing.Point(168, 256)
Me.Delete.Name = "Delete"
Me.Delete.Size = New System.Drawing.Size(68, 24)
Me.Delete.TabIndex = 6
Me.Delete.Text = "Delete"
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT exp_desc, exp_id,
exp_solution FROM msp_explanatory_codes WHERE (exp_id = " & _
"?)"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
Me.OleDbSelectCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO
msp_explanatory_codes(exp_desc, exp_id, exp_solution) VALUES (?, ?, ?"
& _
")"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180, "exp_desc"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbInsertCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240, "exp_solution"))
'
'OleDbUpdateCommand1
'
Me.OleDbUpdateCommand1.CommandText = "UPDATE
msp_explanatory_codes SET exp_desc = ?, exp_id = ?, exp_solution = ?
WHERE" & _
" (exp_id = ?) AND (exp_desc = ?) AND (exp_solution = ? OR ?
IS NULL AND exp_solu" & _
"tion IS NULL)"
Me.OleDbUpdateCommand1.Connection = Me.OleDbConnection1
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180, "exp_desc"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2, "exp_id"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240, "exp_solution"))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_desc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbUpdateCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution1",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
'
'OleDbDeleteCommand1
'
Me.OleDbDeleteCommand1.CommandText = "DELETE FROM
msp_explanatory_codes WHERE (exp_id = ?) AND (exp_desc = ?) AND (exp_"
& _
"solution = ? OR ? IS NULL AND exp_solution IS NULL)"
Me.OleDbDeleteCommand1.Connection = Me.OleDbConnection1
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_id",
System.Data.OleDb.OleDbType.VarWChar, 2,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_id", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_desc",
System.Data.OleDb.OleDbType.VarWChar, 180,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_desc", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
Me.OleDbDeleteCommand1.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_exp_solution1",
System.Data.OleDb.OleDbType.VarWChar, 240,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "exp_solution", System.Data.DataRowVersion.Original, Nothing))
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 294)
Me.Controls.Add(Me.Delete)
Me.Controls.Add(Me.save)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.ExplanatoryDataSet1,
System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.ExpCodesDataSet1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ExpCodesDataSet1.Clear()
Me.OleDbDataAdapter2.Fill(Me.ExpCodesDataSet1)
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.TextChanged
Me.OleDbDataAdapter1.SelectCommand.Parameters.Item(0).Value =
Me.ComboBox1.Text
Me.ExplanatoryDataSet1.Clear()
Me.OleDbDataAdapter1.Fill(Me.ExplanatoryDataSet1)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.OleDbDataAdapter1.SelectCommand.Parameters.Item(0).Value =
Me.ComboBox1.SelectedValue
Me.ExplanatoryDataSet1.Clear()
Me.OleDbDataAdapter1.Fill(Me.ExplanatoryDataSet1)
End Sub
Private Sub save_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles save.Click
MsgBox(Me.ExplanatoryDataSet1.HasChanges.ToString)
result = Me.OleDbDataAdapter1.Update(Me.ExplanatoryDataSet1)
MsgBox(result.ToString)
End Sub
End Class
Thanks!