Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have never been to any technical site that shows concern just to anybody with problems...I look forward to also share in the future..."

Geography

Where in the world do Tek-Tips members come from?
knight33 (IS/IT--Management)
4 Jul 12 6:31
Hello, I do not speak English, it's Google who made the translation into French.

My problem is that I can not make a en.vb.net 2010 or a Do While loop that checks the FOR (IsDBNulle) of 30 TextBox, that's the loop that I wrote but si'il a field vacuum in the Access database following error "the error is always" the exception has been handled InvalideCastException "
"Conversion from type 'DBNull to type' string 'is invalid"
With you I hope a solution to my problem and thank you in advance


I have many text boxes on one form (about 30).
Is there anyway to check them all at once to see if they are « IsDBNull » or empty instead of writing out a massive line of code to check each one individually such as

CODE --> vb.net

‘1
If IsDBNull(ds.Tables("Decision").Rows(Place_Enregistrement).Item("Decentralises")) Then
            Me.TB_Decentralises1.Text = ""
        Else
            Me.TB_Decentralises1.Text = ds.Tables("Decision").Rows(Place_).Item(15)
        End If
‘2
If IsDBNull(ds.Tables("Decision").Rows(Place_Enregistrement).Item("Decentralises")) Then
            Me.TB_Decentralises2.Text = ""
        Else
            Me.TB_Decentralises2.Text = ds.Tables("Decision").Rows(Place_).Item(16)
        End If
‘3
…

Example my "do while", but does not empty fields.

Dim i As Integer
        Dim j As Integer
        i = 0
        j = 16
Do While IsDBNull(ds.Tables("Decision").Rows.Count - 1 < i) = False
            'Do While IsDBNull(ds.Tables("Decision").Rows.Count - 1 <> i) = False
            If IsDBNull(ds.Tables("Decision").Rows(i).Item(j)) Then
                Me. TB_Decentralises1.Text = ""
                Me. TB_Decentralises2.Text = ""
                Me. TB_Decentralises3.Text = ""

            Else
                Me. TB_Decentralises1.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(16))
                Me. TB_Decentralises2.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(17))
                Me. TB_Decentralises3.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(18))
                Exit Do
            End If
            i = i + 1
        Loop 
thank you.
Antzelinaki (Programmer)
4 Jul 12 7:33
You're getting this error because you have written in wrong way the condition. All the arguments must be an index as integer and not a string. for example
dschapters.Tables(0).Rows(0).item(0)
dschapters.Tables(0).Rows(0).item(1)

Your if statement must me like that
If IsDBNull(ds.Tables(0).Rows(0).Item(0)) Then
end if
The first index represent the number of the table, the second the number of ther row and the last one the column index is the item.
So you just have to determine via integer number the index of the table, the index of the row and the index of item as integer each one and not a string. You can also see it in vb.net help. Hope it helps.
knight33 (IS/IT--Management)
4 Jul 12 8:39
Thank you "Antzelinaki" your help, I will try to solve the problem...
Andrzejek (Programmer)
4 Jul 12 15:27

or you may try to add an empty string at the end:

CODE

Me.TB_Decentralises1.Text = ds.Tables("Decision").Rows(Place_).Item(15) & "" 

so if your field happens to be a NULL, you will get an empty string instead. No check for NULL needed

Have fun.

---- Andy

knight33 (IS/IT--Management)
8 Jul 12 5:02
Hello, friends
I will try your method "Andrzejak" thank you.
I have solved my problem this way and it works, it's just art?.

CODE --> vb.net

Dim i As Integer
        Dim j As Integer
        i = 0
        Do While IsDBNull(ds.Tables("Decision").Rows.Count - 1 <> i) = False
            If IsDBNull(ds.Tables("Decision").Rows(i).Item(0)).ToString Then
                Me.txtRub1Detail.Text = ""
                Me.txtRub12Detail.Text = ""
                Me.txtRub13Detail.Text = ""
            Else
                Me.txtRub1Detail.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(16)).ToString
                Me.txtRub12Detail.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(17)).ToString
                Me.txtRub13Detail.Text = (ds.Tables("Decision").Rows(Place_Enregistrement).Item(18)).ToString
                Exit Do
            End If
            i = i + 1
            Loop 

A+

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close