|
-
May 25th, 2003, 05:40 AM
#1
Thread Starter
Hyperactive Member
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:
DA = New OleDbDataAdapter(Query, myConnString)
Dim CB As New OleDb.OleDbCommandBuilder(DA)
DA.InsertCommand = CB.GetInsertCommand
DA.UpdateCommand = CB.GetUpdateCommand
DA.DeleteCommand = CB.GetDeleteCommand
Try
DA.Fill(DS, Table) ' This is where I get the generic error
Catch e As OleDbException ' I added this code
Try
DA.FillSchema(DS, SchemaType.Mapped, Table)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
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...
-
May 25th, 2003, 08:27 AM
#2
Frenzied Member
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
-
May 25th, 2003, 08:30 AM
#3
Thread Starter
Hyperactive Member
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...
-
May 25th, 2003, 08:33 AM
#4
Frenzied Member
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
-
May 25th, 2003, 08:53 AM
#5
Thread Starter
Hyperactive Member
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...
-
May 25th, 2003, 11:34 AM
#6
Fanatic Member
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.
-
May 25th, 2003, 04:22 PM
#7
Thread Starter
Hyperactive Member
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...
-
May 25th, 2003, 04:46 PM
#8
Frenzied Member
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
-
May 25th, 2003, 05:10 PM
#9
Thread Starter
Hyperactive Member
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...
-
May 25th, 2003, 05:15 PM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|