Error on databinding textboxes

Posted on 2007-10-10
Last Modified: 2010-04-23
I have an aspx page, where on pageload I populate textboxes and ddls with info from a sql database. Sometimes, the fields are NULL, and sometimes I get an error, while other times it works fine. Do you know why I get this error and how I can prevent it?  The error always come on line: "strDtFiled = objDR("DateFiled")"  Here is some of my code:

Dim strConn As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True;User Instance=True"
        Dim sql As String = "Select * FROM Orders Where OrdersID = " & list1.SelectedItem.Value
        Dim conn As New SqlConnection(strConn)
        Dim objDR As SqlDataReader
        Dim Cmd As New SqlCommand(sql, conn)
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
        While objDR.Read()
            intID = objDR("OrdersID")
            strDate = objDR("DateTimeReceived")
            strCltFile = objDR("ClientFileNumber")
            strDtFiled = objDR("DateFiled")
            strHrDate = objDR("HearingDate")
            strLstDay = objDR("LastDay")
            strSrvComm = objDR("ServiceComments")
            strAffFileNum = objDR("AffiliateFileNumber")
            strCaseNum = objDR("CaseNumber")
            strHrTime = objDR("HearingTime")
            strCtDept = objDR("CourtDept")
            strPlaintiff = objDR("Plaintiff")
            strDefendant = objDR("Defendant")
            strMailDate = objDR("MailedDate")
            strMailCity = objDR("MailedCity")
            strSvcFee = objDR("ServiceFee")
            'strInvMsg = objDR("InvoiceMessage")
        End While
Question by:mlg101
    1 Comment
    LVL 46

    Accepted Solution

    Hi mlg101,

    Try forcing a string like this....

        strDtFiled = objDR("DateFiled").ToString()



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now