PC Review


Reply
Thread Tools Rate Thread

Database Access with Visual Basic .Net, 3rd edition - problem in example code, any ideas?

 
 
Bob of the West
Guest
Posts: n/a
 
      16th Mar 2004
Hi all,
Anyone have this book? I've run into an example that doesn't work, and
can't relax until I understand what's wrong!

Listing 1.4, p45 ( see below )
In the book it says 'If e.Row.Item "FirstName") = "" 'etc.

But the downloadable code says 'If e.Row.Item("FirstName").length = 0

Neither seem to work. I get "An unhandled exception of type
'System.Data.DeletedRowInaccessibleException' occurred in
system.data.dll Additional information: Deleted row information cannot
be accessed through the row."

Anyone already figured it out? There's no 'errata' section on the
publishers web site ( though you can download the source code )

Best wishes,
P

This is the subroutine:

Private Sub SqlDataAdapter1_RowUpdating(ByVal sender As Object, ByVal
e As System.Data.SqlClient.SqlRowUpdatingEventArgs) _
Handles SqlDataAdapter1.RowUpdating
'this line is in the ownload code
'If e.Row.Item("FirstName") = "" Or e.Row.Item("LastName") =
"" Then
'this line is in the book
If e.Row.Item("FirstName").length = 0 Or
e.Row.Item("LastName").length = 0 Then
MsgBox("Changes not Saved;Customer must have a first and
last name.")
e.Status = UpdateStatus.SkipCurrentRow
e.Row.RejectChanges()
End If
End Sub
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      16th Mar 2004
Hi Bob,

Let I first say that I find this the most crazy place to test a value, this
can be in a class far away from your UI. But than a solution for your
problem. (Let say I give you the solution while I am protesting)

I think that if you insert this, it will go (and to do it better I also
inserted those ToString

If e.Row.RowState = DataRowState.Modified Then
If e.Row.Item("FirstName").ToString.length = 0 Or
e.Row.Item("LastName").ToString.length = 0 Then
> MsgBox("Changes not Saved;Customer must have a first and
> last name.")
> e.Status = UpdateStatus.SkipCurrentRow
> e.Row.RejectChanges()
> End If

End If
End Sub

I hope this helps?

Cor


 
Reply With Quote
 
Bob of the West
Guest
Posts: n/a
 
      17th Mar 2004
Hi Cor,
Thanks for the response.

I gave it a go, and this time no execution errors when I play around
with the form, but it's still not doing what it should. See, the book
example is supposed to show how to prevent users from leaving any of
two textbox fields blank before clicking update. I can still leave a
field blank ( eg LastName ) and it'll be updated into the database.
This must be a fairly standard check for textboxes on forms?

Your point about it being a crazy place to test a value - I think I
know what you mean ( I'm only learning ) but I'm beginning to wonder
about this book. Still, only on page 45 so time to improve..


Bob

"Cor" <(E-Mail Removed)> wrote in message news:<e9Ay0$(E-Mail Removed)>...
> Hi Bob,
>
> Let I first say that I find this the most crazy place to test a value, this
> can be in a class far away from your UI. But than a solution for your
> problem. (Let say I give you the solution while I am protesting)
>
> I think that if you insert this, it will go (and to do it better I also
> inserted those ToString
>
> If e.Row.RowState = DataRowState.Modified Then
> If e.Row.Item("FirstName").ToString.length = 0 Or
> e.Row.Item("LastName").ToString.length = 0 Then
> > MsgBox("Changes not Saved;Customer must have a first and
> > last name.")
> > e.Status = UpdateStatus.SkipCurrentRow
> > e.Row.RejectChanges()
> > End If

> End If
> End Sub
>
> I hope this helps?
>
> Cor

 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      17th Mar 2004
Hi Bob,

This is so a crazy place to do this testing.
Think about this scenario (it is only one of them)
- record is readed with an empty textbox
- user has not changed
- message comes that the update will not be done
- but because that it was empty it stays empty
And there are hundreds of scenario's I think for this.

I do not say that this is the best method, but have a look by example at
this.

http://msdn.microsoft.com/library/de...atingtopic.asp


Cor


 
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
Lost all Visual Basic Code for database Thorson Microsoft Access Form Coding 2 15th Jul 2009 06:55 PM
Don't Want To In Visual Basic Hard Code Complete Connection Path To Database clusardi2k@aol.com Microsoft ADO .NET 4 26th May 2006 05:57 PM
Using a form to update Access database records with visual basic code. geoff.burkholder@canada.weatherford.com Microsoft Access Form Coding 2 3rd Mar 2006 05:46 PM
how do i connect to a DBF database from access visual basic code? =?Utf-8?B?YWJhbGRvMTk3Nw==?= Microsoft Access VBA Modules 2 30th Jun 2005 06:32 PM
Problem With Visual Basic And Access Database Victor Cheung Microsoft Access VBA Modules 7 29th Nov 2003 08:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:47 PM.