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

"...Compliments on a fantastic web site. I have learned so much from my threads and even if sometimes I cannot solve the problem, it gives me the reassurance that I am not the only one putting up with it!..."

Geography

Where in the world do Tek-Tips members come from?

objReader.GetString(x) NULL values are a problem with this

DougP (MIS)
2 Aug 12 8:30
If I have null in the tabel the objReader has issues I can't seem to do anything to passify it.
Can't look at it for a NULL cause it can't conatin a NULL and errors no matter what I do.
how do I get around this I just want to put data in text boxes. can some one give me a code snippet , Please. It's having trouble with a Date being Null. Is there something I can put in the DAte field to make it happy. we are trying sto come up with a date that is eitehr 1900 or 2100, so far out then have to check for it. But I have to update all the records. I would prefer to handle the Nulls with this reader. Or can I put something into the SQL string so it returns something other than Null?
Also note I left out some of the = objReader.GetString(x) lines below to save space.

Error >>>>> Data is Null. this property or method cannot be called on Null values.

CODE

Try
            cnn.Open()
            Dim queryTrans As String
            queryTrans = "SELECT ResourceLastname, ResourceFirstname, Manager, " & _
                        "ResourceType, [Offshore-OnShore], Vendor, SOWTracker, StartDate, " & _
                        " EndDate, email,intUserId  From SOWResources " & _
                        "WHERE ResourceLastname = '" & Lname & "' " & _
                "AND ResourceFirstname = '" & Fname & "' 

Dim strConn As New SqlConnection(connStr)
            Dim objComm As SqlCommand
            Dim objReader As SqlDataReader
            strConn.Open()
            objComm = New SqlCommand(queryTrans, strConn)
            objReader = objComm.ExecuteReader()

            If objReader.HasRows Then
                Do While objReader.Read()
                    Me.txtResourceLastname.Text = objReader.GetString(0)
                    Me.txtResourceFirstname.Text = objReader.GetString(1)
                    Me.ddlManagerName.Text = objReader.GetString(2)
                    Me.txtResourceType.Text = objReader.GetString(3)
                    Me.ddlShore.Text = objReader.GetString(4)
                    ...
                    Me.txtEndDate.Text = objReader.GetString(8) ' ERROR here the End date is null
                    ' Me.ddlVendor.Text = TheVendor.ToString

                Loop '
            End If 

TIA

DougP

jbenson001 (Programmer)
2 Aug 12 13:53
See if this works for you:

CODE

IIf(objReader.IsDBNull(objReader.GetString(8)), String.Empty, objReader.GetString(8)) 
DougP (MIS)
16 Aug 12 11:37
No jbenson001 , that does not work. I remeber something about needing to test it prior to it geting a NULL cause onec it has a NULL it won't do anything.

Is there something else I can use beside the Reader?
On thing I did as a workaround was put a value in the Date column that's not Null but has no significance. I added another column and this problem came up again. I put a "-" in every row for it but the reader has problems with NULLs. I want to get rid of it or fix perfer geet rid of it.

I need to fill a combo box without using a SQLDataSource, need to do it manually.

DougP

jbenson001 (Programmer)
16 Aug 12 11:47
Instead of using an inline if IIF, use a regular IF statement, something like:

CODE

if objReader.IsDBNull(objReader.GetString(8))
    Me.txtEndDate.Text = string.empty
else
     Me.txtEndDate.Text = objReader.GetString(8)
end if 
Qik3Coder (Programmer)
16 Aug 12 16:02
I give to you the gift of the MSDN!
http://msdn.microsoft.com/en-us/library/system.dat...

CODE

IF objReader.IsDBNull(8) Then
    Me.txtEndDate.Text = string.empty
Else
     Me.txtEndDate.Text = objReader.GetString(8)
End If 

Lodlaiden

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.

MarkSweetland (MIS)
17 Aug 12 8:50


You can use isNull() (SQL Server) to transform NULL entries to an empty string:

CODE

queryTrans = "SELECT ResourceLastname, ResourceFirstname, Manager, " & _
                   "ResourceType, [Offshore-OnShore], Vendor, SOWTracker, StartDate, " & _
                   "EndDate=isNull(EndDate,''), email,intUserId  From SOWResources " & _
                   "WHERE ResourceLastname = '" & Lname & "' " & _
                   "AND ResourceFirstname = '" & Fname & "' 


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach

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