B
barret bonden
Trying to teach myself ADO.NET. Here is the most simple example of a hand
coded use of ADO.NET I could find
(from a SAMS book)
The Access.MDB is OK, and this code does pull up records from it. It fails,
however, on saving with "Syntax error in INSERT INTO statement."
when it hits : m_daDatatadapter.Update(m_dtContacts) .
If anyone can point me to another simple hand coded example I can study and
play with I'd be much obliged.
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDatatadapter As New OleDb.OleDbDataAdapter
Private m_cdCommandbuilder As OleDb.OleDbCommandBuilder
Private m_dtContacts As New DataTable
Private m_rowPosition As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_cnADONetConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test.mdb;"
m_cnADONetConnection.Open()
m_daDatatadapter = New OleDb.OleDbDataAdapter("select * from test",
m_cnADONetConnection)
m_cdCommandbuilder = (New
OleDb.OleDbCommandBuilder(m_daDatatadapter))
m_daDatatadapter.Fill(m_dtContacts)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = m_dtContacts.Rows(m_rowPosition)("last").ToString
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim nr As DataRow = m_dtContacts.NewRow()
nr("last") = TextBox1.Text
'nr("first") = TextBox2.Text
m_dtContacts.Rows.Add(nr)
' ERROR HERE
m_daDatatadapter.Update(m_dtContacts) ' Syntax error in
INSERT INTO statement.
End sub
coded use of ADO.NET I could find
(from a SAMS book)
The Access.MDB is OK, and this code does pull up records from it. It fails,
however, on saving with "Syntax error in INSERT INTO statement."
when it hits : m_daDatatadapter.Update(m_dtContacts) .
If anyone can point me to another simple hand coded example I can study and
play with I'd be much obliged.
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDatatadapter As New OleDb.OleDbDataAdapter
Private m_cdCommandbuilder As OleDb.OleDbCommandBuilder
Private m_dtContacts As New DataTable
Private m_rowPosition As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_cnADONetConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test.mdb;"
m_cnADONetConnection.Open()
m_daDatatadapter = New OleDb.OleDbDataAdapter("select * from test",
m_cnADONetConnection)
m_cdCommandbuilder = (New
OleDb.OleDbCommandBuilder(m_daDatatadapter))
m_daDatatadapter.Fill(m_dtContacts)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = m_dtContacts.Rows(m_rowPosition)("last").ToString
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim nr As DataRow = m_dtContacts.NewRow()
nr("last") = TextBox1.Text
'nr("first") = TextBox2.Text
m_dtContacts.Rows.Add(nr)
' ERROR HERE
m_daDatatadapter.Update(m_dtContacts) ' Syntax error in
INSERT INTO statement.
End sub