Problem with source table update


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem with source table update

  1. #1
    Join Date
    Feb 2005
    Posts
    5

    Question Problem with source table update

    Hi!

    I'm having trouble updating the source table with dataset records that have been added (in VB.NET)

    I have two databases that I want to merge one table at a time. I'm struggling with table number one.

    I manage to get all rows into the "ds" dataset and the rowstate of each is "added".
    When I run the update statement I get an error and no update.
    I added the command builder because I read somewhere it would automatically generate the necessary SQL statements.

    This is the code:

    Dim cn As OleDbConnection = New OleDbConnection(strConnection)

    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & TargetDBFullPath

    dscmd = New OleDbDataAdapter("SELECT * FROM firsttable", cn)

    Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(dscmd)
    cn = New OleDbConnection(strConnection)
    cn.Open()

    cb.QuotePrefix = ("[")
    cb.QuoteSuffix = ("]")

    ds = New DataSet
    dscmd.Fill(ds, "firsttable")

    Dim workrow As DataRow

    For iCtr = 1 To SourceRecordCount
    workrow = ds.Tables("firsttable").NewRow
    'set column values
    ds.Tables("firsttable").Rows.Add(workrow)
    Next

    dscmd.Update(ds, "firsttable")
    cn.Close()

    In the dbs I have a table called "session". Strangely it can't be called that.
    If I change the name to "session1" ,for example, no error occurs.
    Anyone who knows why?

    I would be very happy if someone could help with this.

  2. #2
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    session is a reserved keyword in some languages and I am not sure about in databases but it could be a reason. a few years ago, I had a table named Order and it never worked and after a whole month of investigation I found out that it was just the name of the table which is why I would never get an error nor it would work. Try Sessions if Session1 is not suitable.
    new to programming but getting ther

  3. #3
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    If this is MS-SQL Server, you can bracket the table name, like this:

    [session]

    For instance, in a SELECT command it would be:

    Select * from [session]

    0r

    Select * from MyDB.dbo.[session]

    This also works if you have problems with table names that have spaces, punctuation, etc.

    Hope this helps...
    Bob Rouse
    Dimension Data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center