Results 1 to 10 of 10

Thread: Db empty problem...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325

    Db empty problem...

    When I do a query that selects 0 records I get an error. How to avoid this? Here's my code:
    VB Code:
    1. DA = New OleDbDataAdapter(Query, myConnString)
    2. Dim CB As New OleDb.OleDbCommandBuilder(DA)
    3.  
    4. DA.InsertCommand = CB.GetInsertCommand
    5. DA.UpdateCommand = CB.GetUpdateCommand
    6. DA.DeleteCommand = CB.GetDeleteCommand
    7. Try
    8.     DA.Fill(DS, Table) ' This is where I get the generic error
    9. Catch e As OleDbException ' I added this code
    10.     Try
    11.         DA.FillSchema(DS, SchemaType.Mapped, Table)
    12.     Catch ex As Exception
    13.         MsgBox(ex.ToString)
    14.     End Try
    15. End Try
    There is a peice of code I added to manage this case, but when I add a row to the table and update, the operations goes OK, but I don't have my row in the database.

    Thx
    Learn, this is the Keyword...

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Though not relevant to your post, i think the following lines are not needed:
    DA.InsertCommand = CB.GetInsertCommand
    DA.UpdateCommand = CB.GetUpdateCommand
    DA.DeleteCommand = CB.GetDeleteCommand
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Originally posted by Lunatic3
    Though not relevant to your post, i think the following lines are not needed:
    DA.InsertCommand = CB.GetInsertCommand
    DA.UpdateCommand = CB.GetUpdateCommand
    DA.DeleteCommand = CB.GetDeleteCommand
    Without these lines, sometimes, my datadabe will not be updated, so they aren't so bad at all
    Learn, this is the Keyword...

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    That may have other reasons. I am almost sure that those lines of code wont do anything more than:
    Dim CB As New OleDb.OleDbCommandBuilder(DA)
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    I looked at the local variables, without these lines, commandtexts are Nothing. Maybe it's not important for some types of data, but I noticed that my database without these lines sometimes won't update.
    Learn, this is the Keyword...

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    There may be a better way to get around your exception, but you might run a SQLCommand against your database to Select Count for the table you want, and if it returns 0 then abort the fill.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    The fact is that I still need to fill the dataset, at least with the schema. How can I insert a record if I don't know the schema?
    Learn, this is the Keyword...

  8. #8
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I get no error running your code even when query return 0 records. Make sure you have no reserved words in your database table fileds name.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Originally posted by Lunatic3
    I get no error running your code even when query return 0 records. Make sure you have no reserved words in your database table fileds name.
    I never do one error twice
    Learn, this is the Keyword...

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    Palermo, Italy
    Posts
    325
    Maybe this is a stupid thing I can't figure out now... Maybe tomorrow, when my brain is in peace...
    Learn, this is the Keyword...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width