• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Error on databinding textboxes

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
1 Solution
Wayne Taylor (webtubbs)Commented:
Hi mlg101,

Try forcing a string like this....

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


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now