PC Review


Reply
Thread Tools Rate Thread

Can't Append dBASE File

 
 
Roger Lord
Guest
Posts: n/a
 
      12th Jul 2003
I'm hoping somebody can help me with this and I hope this is the
correct newsgroup. I am writing a VB.NET program that accesses a
dBASE IV file. I can't get a subroutine to actually add a row to
the end of the dBASE file - I keep getting an error (using
Try...Catch...Finally) that says "Syntax error in INSERT INTO
statement". This I can't understand because I'm using
OleDbCommandBuilder to create the INSERT command. The following
is the exact code from my program:


Public Sub Append_Database()

'---- First, set up the connection and the dataset ----
Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=C:\LCTA;" & "Extended Properties=dBase IV"
Dim cn As New OleDbConnection(cs)
cn.Open()

'---- Second, read in the existing data from the server ----
Dim myQuery As String = "SELECT * FROM MEMBERS"
Dim da1 As New OleDbDataAdapter(myQuery, cn)
Dim mDataSet As New DataSet()
da1.Fill(mDataSet, "MEMBERS") 'Fill dataset with dBase table
Members.dbf

Dim cb As New OleDbCommandBuilder(da1) 'This builds the
INSERT, UPDATE, and DELETE commands

'---- Now define what will be a new row ----
Dim myRow As Data.DataRow
myRow = mDataSet.Tables("MEMBERS").NewRow
myRow("LASTNAME") = UCase(txtLastName.Text)
myRow("FIRST") = UCase(txtFirstName.Text)
myRow("MIDDLE") = UCase(txtMiddleInit.Text)
myRow("STREET1") = UCase(txtAddress1.Text)
myRow("STREET2") = UCase(txtAddress2.Text)
myRow("TOWN") = UCase(txtCity.Text)
myRow("STATE") = UCase(txtState.Text)
myRow("ZIP") = txtZip.Text
myRow("HOMETEL") = UCase(txtHomeTel.Text)
myRow("WORKTEL") = UCase(txtWorkTel.Text)
myRow("EXTENSION") = UCase(txtExt.Text)
myRow("EMAIL") = txtEmail.Text
myRow("WIFE_FIRST") = UCase(txtSpouseFirst.Text)
myRow("WIFE_MI") = UCase(txtSpouseMI.Text)
myRow("WIFE_LAST") = UCase(txtSpouseLast.Text)
myRow("JOINED") = CDate(txtJoined.Text)
myRow("LASTPAID") = CDate(txtLastContrib.Text)
myRow("AMOUNT") = Val(txtAmount.Text)

'---- Now add the new row to the dataset
mDataSet.Tables("MEMBERS").Rows.Add(myRow)

'---- Finally, update the database on the server from the
revised dataset
Try
da1.Update(mDataSet, "MEMBERS")
Catch e As OleDb.OleDbException
MsgBox(e.Message)
Finally
cn.Close()
End Try
End Sub



The exception occurs at the statement: da1.Update(mDataSet,
"MEMBERS")



Any ideas what's wrong?



Thanks,

Roger



 
Reply With Quote
 
 
 
 
Roger Lord
Guest
Posts: n/a
 
      12th Jul 2003
Carsten,

I was just ready to try your suggestion when I stumbled on to
something in a book that looked a little easier. Evidently, the
OLE command builder was using quotation marks in creating the
INSERT command and that, supposedly, was causing the syntax
error. The book used the following to solve the problem... and
it worked!


Dim cb As New OleDbCommandBuilder(da1)
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"

The fact that the object has properties of QuotePrefix and
QuoteSuffix tells me that this is an expected situation. I'm not
sure why the command builder just doesn't make the changes
automatically. But thanks for your input nevertheless. I will
probably still need to write my own INSERT command someday.

Roger



"CT" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Have you tried examining the INSERT statement, and perhaps
creating your
own? I've seen this before with ODBC drivers; it seems that the
CommandBuilder doesn't handle them all very well.

--
Carsten Thomsen
Enterprise Development with Visual Studio .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Roger Lord" <(E-Mail Removed)> wrote in message
news:Q9JPa.7912$b03.2844@lakeread03...
> I'm hoping somebody can help me with this and I hope this is

the
> correct newsgroup. I am writing a VB.NET program that accesses

a
> dBASE IV file. I can't get a subroutine to actually add a row

to
> the end of the dBASE file - I keep getting an error (using
> Try...Catch...Finally) that says "Syntax error in INSERT INTO
> statement". This I can't understand because I'm using
> OleDbCommandBuilder to create the INSERT command. The

following
> is the exact code from my program:
>
>
> Public Sub Append_Database()
>
> '---- First, set up the connection and the dataset ----
> Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
> "Data Source=C:\LCTA;" & "Extended Properties=dBase IV"
> Dim cn As New OleDbConnection(cs)
> cn.Open()
>
> '---- Second, read in the existing data from the

server ----
> Dim myQuery As String = "SELECT * FROM MEMBERS"
> Dim da1 As New OleDbDataAdapter(myQuery, cn)
> Dim mDataSet As New DataSet()
> da1.Fill(mDataSet, "MEMBERS") 'Fill dataset with dBase

table
> Members.dbf
>
> Dim cb As New OleDbCommandBuilder(da1) 'This builds the
> INSERT, UPDATE, and DELETE commands
>
> '---- Now define what will be a new row ----
> Dim myRow As Data.DataRow
> myRow = mDataSet.Tables("MEMBERS").NewRow
> myRow("LASTNAME") = UCase(txtLastName.Text)
> myRow("FIRST") = UCase(txtFirstName.Text)
> myRow("MIDDLE") = UCase(txtMiddleInit.Text)
> myRow("STREET1") = UCase(txtAddress1.Text)
> myRow("STREET2") = UCase(txtAddress2.Text)
> myRow("TOWN") = UCase(txtCity.Text)
> myRow("STATE") = UCase(txtState.Text)
> myRow("ZIP") = txtZip.Text
> myRow("HOMETEL") = UCase(txtHomeTel.Text)
> myRow("WORKTEL") = UCase(txtWorkTel.Text)
> myRow("EXTENSION") = UCase(txtExt.Text)
> myRow("EMAIL") = txtEmail.Text
> myRow("WIFE_FIRST") = UCase(txtSpouseFirst.Text)
> myRow("WIFE_MI") = UCase(txtSpouseMI.Text)
> myRow("WIFE_LAST") = UCase(txtSpouseLast.Text)
> myRow("JOINED") = CDate(txtJoined.Text)
> myRow("LASTPAID") = CDate(txtLastContrib.Text)
> myRow("AMOUNT") = Val(txtAmount.Text)
>
> '---- Now add the new row to the dataset
> mDataSet.Tables("MEMBERS").Rows.Add(myRow)
>
> '---- Finally, update the database on the server from the
> revised dataset
> Try
> da1.Update(mDataSet, "MEMBERS")
> Catch e As OleDb.OleDbException
> MsgBox(e.Message)
> Finally
> cn.Close()
> End Try
> End Sub
>
>
>
> The exception occurs at the statement: da1.Update(mDataSet,
> "MEMBERS")
>
>
>
> Any ideas what's wrong?
>
>
>
> Thanks,
>
> Roger
>
>
>





 
Reply With Quote
 
copyco
Guest
Posts: n/a
 
      13th Jul 2003
I think the cb.QuotePrefix = "]", etc. puts brackets around the field
names in the command. This is to avoid problems when field names are
also reserved words. So you probably have a field name that is a
reserved word. I had this problem when one of my field names was "number".


Roger Lord wrote:

> Carsten,
>
> I was just ready to try your suggestion when I stumbled on to
> something in a book that looked a little easier. Evidently, the
> OLE command builder was using quotation marks in creating the
> INSERT command and that, supposedly, was causing the syntax
> error. The book used the following to solve the problem... and
> it worked!
>
>
> Dim cb As New OleDbCommandBuilder(da1)
> cb.QuotePrefix = "["
> cb.QuoteSuffix = "]"
>
> The fact that the object has properties of QuotePrefix and
> QuoteSuffix tells me that this is an expected situation. I'm not
> sure why the command builder just doesn't make the changes
> automatically. But thanks for your input nevertheless. I will
> probably still need to write my own INSERT command someday.
>
> Roger
>
>
>
> "CT" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> Have you tried examining the INSERT statement, and perhaps
> creating your
> own? I've seen this before with ODBC drivers; it seems that the
> CommandBuilder doesn't handle them all very well.
>
> --
> Carsten Thomsen
> Enterprise Development with Visual Studio .NET, UML, and MSF
> http://www.apress.com/book/bookDisplay.html?bID=105
> "Roger Lord" <(E-Mail Removed)> wrote in message
> news:Q9JPa.7912$b03.2844@lakeread03...
>
>>I'm hoping somebody can help me with this and I hope this is

>
> the
>
>>correct newsgroup. I am writing a VB.NET program that accesses

>
> a
>
>>dBASE IV file. I can't get a subroutine to actually add a row

>
> to
>
>>the end of the dBASE file - I keep getting an error (using
>>Try...Catch...Finally) that says "Syntax error in INSERT INTO
>>statement". This I can't understand because I'm using
>>OleDbCommandBuilder to create the INSERT command. The

>
> following
>
>>is the exact code from my program:
>>
>>
>>Public Sub Append_Database()
>>
>> '---- First, set up the connection and the dataset ----
>> Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
>>"Data Source=C:\LCTA;" & "Extended Properties=dBase IV"
>> Dim cn As New OleDbConnection(cs)
>> cn.Open()
>>
>> '---- Second, read in the existing data from the

>
> server ----
>
>> Dim myQuery As String = "SELECT * FROM MEMBERS"
>> Dim da1 As New OleDbDataAdapter(myQuery, cn)
>> Dim mDataSet As New DataSet()
>> da1.Fill(mDataSet, "MEMBERS") 'Fill dataset with dBase

>
> table
>
>>Members.dbf
>>
>> Dim cb As New OleDbCommandBuilder(da1) 'This builds the
>>INSERT, UPDATE, and DELETE commands
>>
>> '---- Now define what will be a new row ----
>> Dim myRow As Data.DataRow
>> myRow = mDataSet.Tables("MEMBERS").NewRow
>> myRow("LASTNAME") = UCase(txtLastName.Text)
>> myRow("FIRST") = UCase(txtFirstName.Text)
>> myRow("MIDDLE") = UCase(txtMiddleInit.Text)
>> myRow("STREET1") = UCase(txtAddress1.Text)
>> myRow("STREET2") = UCase(txtAddress2.Text)
>> myRow("TOWN") = UCase(txtCity.Text)
>> myRow("STATE") = UCase(txtState.Text)
>> myRow("ZIP") = txtZip.Text
>> myRow("HOMETEL") = UCase(txtHomeTel.Text)
>> myRow("WORKTEL") = UCase(txtWorkTel.Text)
>> myRow("EXTENSION") = UCase(txtExt.Text)
>> myRow("EMAIL") = txtEmail.Text
>> myRow("WIFE_FIRST") = UCase(txtSpouseFirst.Text)
>> myRow("WIFE_MI") = UCase(txtSpouseMI.Text)
>> myRow("WIFE_LAST") = UCase(txtSpouseLast.Text)
>> myRow("JOINED") = CDate(txtJoined.Text)
>> myRow("LASTPAID") = CDate(txtLastContrib.Text)
>> myRow("AMOUNT") = Val(txtAmount.Text)
>>
>> '---- Now add the new row to the dataset
>> mDataSet.Tables("MEMBERS").Rows.Add(myRow)
>>
>> '---- Finally, update the database on the server from the
>>revised dataset
>> Try
>> da1.Update(mDataSet, "MEMBERS")
>> Catch e As OleDb.OleDbException
>> MsgBox(e.Message)
>> Finally
>> cn.Close()
>> End Try
>>End Sub
>>
>>
>>
>>The exception occurs at the statement: da1.Update(mDataSet,
>>"MEMBERS")
>>
>>
>>
>>Any ideas what's wrong?
>>
>>
>>
>>Thanks,
>>
>>Roger
>>
>>
>>

>
>
>
>
>


 
Reply With Quote
 
Roger Lord
Guest
Posts: n/a
 
      13th Jul 2003
Dear Sir:

You are probably correct on that. Do you have any idea which of
my field names might be a reserved word so that I avoid using
them in the future? The list of them that I am using is:

LASTNAME
FIRST
MIDDLE
STREET1
STREET2
TOWN
STATE
ZIP
HOMETEL
WORKTEL
EXTENSION
EMAIL
WIFE_FIRST
WIFE_MI
WIFE_LAST
JOINED
LASTPAID
AMOUNT

I typed in a few of them in Help's Index, but nothing in
particular came up.

Thanks,
Roger


"copyco" <(E-Mail Removed)> wrote in message
news:Si4Qa.620$(E-Mail Removed)...
I think the cb.QuotePrefix = "]", etc. puts brackets around the
field
names in the command. This is to avoid problems when field names
are
also reserved words. So you probably have a field name that is a
reserved word. I had this problem when one of my field names was
"number".


Roger Lord wrote:

> Carsten,
>
> I was just ready to try your suggestion when I stumbled on to
> something in a book that looked a little easier. Evidently,

the
> OLE command builder was using quotation marks in creating the
> INSERT command and that, supposedly, was causing the syntax
> error. The book used the following to solve the problem... and
> it worked!
>
>
> Dim cb As New OleDbCommandBuilder(da1)
> cb.QuotePrefix = "["
> cb.QuoteSuffix = "]"
>
> The fact that the object has properties of QuotePrefix and
> QuoteSuffix tells me that this is an expected situation. I'm

not
> sure why the command builder just doesn't make the changes
> automatically. But thanks for your input nevertheless. I will
> probably still need to write my own INSERT command someday.
>
> Roger
>
>
>
> "CT" <(E-Mail Removed)> wrote in

message
> news:(E-Mail Removed)...
> Have you tried examining the INSERT statement, and perhaps
> creating your
> own? I've seen this before with ODBC drivers; it seems that the
> CommandBuilder doesn't handle them all very well.
>
> --
> Carsten Thomsen
> Enterprise Development with Visual Studio .NET, UML, and MSF
> http://www.apress.com/book/bookDisplay.html?bID=105
> "Roger Lord" <(E-Mail Removed)> wrote in message
> news:Q9JPa.7912$b03.2844@lakeread03...
>
>>I'm hoping somebody can help me with this and I hope this is

>
> the
>
>>correct newsgroup. I am writing a VB.NET program that accesses

>
> a
>
>>dBASE IV file. I can't get a subroutine to actually add a row

>
> to
>
>>the end of the dBASE file - I keep getting an error (using
>>Try...Catch...Finally) that says "Syntax error in INSERT INTO
>>statement". This I can't understand because I'm using
>>OleDbCommandBuilder to create the INSERT command. The

>
> following
>
>>is the exact code from my program:
>>
>>
>>Public Sub Append_Database()
>>
>> '---- First, set up the connection and the dataset ----
>> Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
>>"Data Source=C:\LCTA;" & "Extended Properties=dBase IV"
>> Dim cn As New OleDbConnection(cs)
>> cn.Open()
>>
>> '---- Second, read in the existing data from the

>
> server ----
>
>> Dim myQuery As String = "SELECT * FROM MEMBERS"
>> Dim da1 As New OleDbDataAdapter(myQuery, cn)
>> Dim mDataSet As New DataSet()
>> da1.Fill(mDataSet, "MEMBERS") 'Fill dataset with dBase

>
> table
>
>>Members.dbf
>>
>> Dim cb As New OleDbCommandBuilder(da1) 'This builds the
>>INSERT, UPDATE, and DELETE commands
>>
>> '---- Now define what will be a new row ----
>> Dim myRow As Data.DataRow
>> myRow = mDataSet.Tables("MEMBERS").NewRow
>> myRow("LASTNAME") = UCase(txtLastName.Text)
>> myRow("FIRST") = UCase(txtFirstName.Text)
>> myRow("MIDDLE") = UCase(txtMiddleInit.Text)
>> myRow("STREET1") = UCase(txtAddress1.Text)
>> myRow("STREET2") = UCase(txtAddress2.Text)
>> myRow("TOWN") = UCase(txtCity.Text)
>> myRow("STATE") = UCase(txtState.Text)
>> myRow("ZIP") = txtZip.Text
>> myRow("HOMETEL") = UCase(txtHomeTel.Text)
>> myRow("WORKTEL") = UCase(txtWorkTel.Text)
>> myRow("EXTENSION") = UCase(txtExt.Text)
>> myRow("EMAIL") = txtEmail.Text
>> myRow("WIFE_FIRST") = UCase(txtSpouseFirst.Text)
>> myRow("WIFE_MI") = UCase(txtSpouseMI.Text)
>> myRow("WIFE_LAST") = UCase(txtSpouseLast.Text)
>> myRow("JOINED") = CDate(txtJoined.Text)
>> myRow("LASTPAID") = CDate(txtLastContrib.Text)
>> myRow("AMOUNT") = Val(txtAmount.Text)
>>
>> '---- Now add the new row to the dataset
>> mDataSet.Tables("MEMBERS").Rows.Add(myRow)
>>
>> '---- Finally, update the database on the server from the
>>revised dataset
>> Try
>> da1.Update(mDataSet, "MEMBERS")
>> Catch e As OleDb.OleDbException
>> MsgBox(e.Message)
>> Finally
>> cn.Close()
>> End Try
>>End Sub
>>
>>
>>
>>The exception occurs at the statement: da1.Update(mDataSet,
>>"MEMBERS")
>>
>>
>>
>>Any ideas what's wrong?
>>
>>
>>
>>Thanks,
>>
>>Roger
>>
>>
>>

>
>
>
>
>




 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      14th Jul 2003
On Sun, 13 Jul 2003 08:15:17 -0400, "Roger Lord" <(E-Mail Removed)> wrote:

¤ Dear Sir:
¤
¤ You are probably correct on that. Do you have any idea which of
¤ my field names might be a reserved word so that I avoid using
¤ them in the future? The list of them that I am using is:
¤
¤ LASTNAME
¤ FIRST
¤ MIDDLE
¤ STREET1
¤ STREET2
¤ TOWN
¤ STATE
¤ ZIP
¤ HOMETEL
¤ WORKTEL
¤ EXTENSION
¤ EMAIL
¤ WIFE_FIRST
¤ WIFE_MI
¤ WIFE_LAST
¤ JOINED
¤ LASTPAID
¤ AMOUNT
¤
¤ I typed in a few of them in Help's Index, but nothing in
¤ particular came up.

I don't see any reserved words above. I would try using the process of elimination. Remove fields
from the DataRow your are adding until you have a successful update. I would start with the Date
fields.


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to create dbase file from text file? Hilton Microsoft Excel Misc 0 9th Oct 2008 10:37 AM
Creating an Access database file from a dbf (dbase) file =?Utf-8?B?RnJ5cGFuSmFjaw==?= Microsoft Access External Data 5 22nd Feb 2007 05:20 PM
CSV-File TO DBASE III novelle Microsoft VB .NET 0 19th Oct 2006 02:49 PM
Prompting for a file name when linking to dBASE file =?Utf-8?B?RGFuIEhlbnNvbg==?= Microsoft Access Queries 1 3rd Mar 2006 08:19 PM
How do I append my one Access dbase with data from many different. =?Utf-8?B?Z3lwc3k=?= Microsoft Access External Data 1 2nd Oct 2004 09:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 PM.