Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Distributed Applications / May 2004

Tip: Looking for answers? Try searching our database.

Using OleDBDataAdapter.Update with Access I get Syntax error in UPDATE statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig Clark - 03 May 2004 17:11 GMT
Hi

I have just started developing in VB.net 2003.  I want to us the OleDBDataAdapter.Update(dataset,tablename) method.  It work just fine with MS Sql Server 2000 but when I use the same code with Access, I get an "Syntax error in UPDATE statement".  Do I need to do something different with Access (Office Access 2003)???

Any Ideas would be greatly appreciated
Crai

Here is the test code (modified from the MS sample code)
Imports Syste
Imports System.Dat
Imports System.Data.OleD

Module Module
  Dim sTableName As Strin
  Dim sConnectionString As Strin
  Public Const cDataSource = "Data Source=
  Public Const cCatalog = "Initial Catalog=
  Public Const cProvider = "Provider=
  Public Const cUserId = "User ID=
  Public Const cPassword = "Password=
  Public Const cSecurity = "Persist Security Info=
  Dim sDBName As Strin
  Dim sProvider As Strin
  Dim sSecurity As Strin
  Dim sUserId As Strin
  Dim sDataSource As Strin
  Dim sCatalog As Strin
  Dim sPassword As Strin

  Sub Main(
     Dim myConnection As OleDbConnectio
     Dim myOleDBDataAdapter As OleDbDataAdapte

     Console.WriteLine("Enter 1 for Access or 2 for SQL"
     If (Console.ReadLine <> "1") The
        sTableName = "Customers
        sProvider = "sqloledb
        sSecurity = "True
        sDataSource = "TestSQL
        sCatalog = "Northwind
        sUserId = "sa
        sPassword = "12345
     Els
        sTableName = "Titles
        sProvider = "Microsoft.jet.oledb.4.0
        sSecurity = "
        sDataSource = "c:\program Files\Microsoft Visual Studio\VB98\Biblio.mdb
        sCatalog = "
        sUserId = "admin
        sPassword = "  
     End I

     myConnection = New OleDbConnection(formatConnectionString()
     myOleDBDataAdapter = New OleDbDataAdapte
     myOleDBDataAdapter.SelectCommand = New OleDbCommand("select * from " & sTableName, myConnection
     Dim myDataSet As DataSet = New DataSe
     Dim myDataRow As DataRo
     Dim myDataRowsCommandBuilder As OleDbCommandBuilder = New OleDbCommandBuilder(myOleDBDataAdapter

     myOleDBDataAdapter.Fill(myDataSet, sTableName
     Console.WriteLine("Loaded data from " & sTableName & " table into dataset (" & Str(myDataSet.Tables(0).Rows.Count) & ")."
     myOleDBDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKe

     If (sTableName = "Customers") The
        myDataSet.Tables(0).Rows(0).Item(2) = "Peach
        Console.WriteLine("Edited data Row 1, column 3 = Peach)."
     Els
        myDataSet.Tables(0).Rows(0).Item(1) = 199
        Console.WriteLine("Edited data Row 1, column 3 = 1999)."
     End I

     Tr
        myOleDBDataAdapter.Update(myDataSet, sTableName
        Console.WriteLine("Sent Update to database."
        Console.WriteLine("DataSet processing has completed successfully!"
     Catch ex As Exceptio
        Console.WriteLine("Update to database FAILED."
        Console.WriteLine(ex.Message
     End Tr

     myConnection.Close(
     Console.Write("Press Enter to continue... "
     Console.ReadLine(

  End Su
  Private Function formatConnectionString() As Strin
     Dim ConnectionString As Strin
     ConnectionString = "
     If Len(Trim(sProvider)) > 0 The
        ConnectionString = ConnectionString & cProvider & sProvider & ";
     End I
     If Len(Trim(sPassword)) > 0 The
        ConnectionString = ConnectionString & cPassword & sPassword & ";
     End I
     If Len(Trim(sSecurity)) > 0 The
        ConnectionString = ConnectionString & cSecurity & sSecurity & ";
     End I
     If Len(Trim(sUserId)) > 0 The
        ConnectionString = ConnectionString & cUserId & sUserId & ";
     End I
     If Len(Trim(sCatalog)) > 0 The
        ConnectionString = ConnectionString & cCatalog & sCatalog & ";
     End I
     If Len(Trim(sDataSource)) > 0 The
        ConnectionString = ConnectionString & cDataSource & sDataSource & ";
     End I

     formatConnectionString = ConnectionStrin
  End Functio

End Modul
Jens Burup - 27 May 2004 17:18 GMT
> Hi,
>
> I have just started developing in VB.net 2003.  I want to us the OleDBDataAdapter.Update(dataset,tablename) method.  It work just fine with
MS Sql Server 2000 but when I use the same code with Access, I get an
"Syntax error in UPDATE statement".  Do I need to do something different
with Access (Office Access 2003)???

> Any Ideas would be greatly appreciated.
> Craig
[quoted text clipped - 103 lines]
>
> End Module

You can't use exact the same connectionstring by just changing OleSql to
oleDB.
I suggest you try to make a OleDBconnection from the toolbox to look up the
correct string.

Regards Jens Burup

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.