[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • 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)
        conn.Open()
        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
        Page.DataBind()
        conn.Close()
0
mlg101
Asked:
mlg101
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Hi mlg101,

Try forcing a string like this....

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

Regards,

Wayne
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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