开发者

aspx.net website connecting to an SQL server

I am Trying to add some information to a data base server, a person's ID, the experiment he is participating in, and the date of the experiment.

This is my code:

SQLConnection1.ConnectionString = MyConn
Dim drNewRow As DataRow = DtsLabSyst开发者_Python百科em1.tables("SubjectExperiment").NewRow

drNewRow("SubjectID") = lblSubjectID.Text
drNewRow("ExperimentID") = Request.Form("ExpSelectID")


Dim strDate As String
strDate = "#" & ddlDay.SelectedValue & "/" & ddlMonth.SelectedValue & "/" & txtYear.Text & "#"


If IsDate(strDate) Then
       If MyConn = "THE external SERVER CONNECTION STRING" Then
            'we are connected to the linux data base
            drNewRow("ExpDate") = CDate(ddlDay.SelectedValue & "/" & ddlMonth.SelectedValue & "/" & txtYear.Text)

        Else
            'we are connected to the local data base
            drNewRow("ExpDate") = CDate(ddlDay.SelectedValue & "/" & ddlMonth.SelectedValue & "/" & txtYear.Text)

        End If

    Else
        drNewRow("ExpDate") = CDate("01/01/9999")

    End If

    drNewRow("Comment") = txtComment.Text

    DtsLabSystem1.tables("SubjectExperiment").Rows.Add(drNewRow)
    SQLDataAdapter1.Update(DtsLabSystem1.tables("SubjectExperiment"))

    Response.Redirect("SubjectDetails.aspx?ID=" & lblSubjectID.Text)

End Function

My problem is that when redirecting to SubjectDetails.aspx, I try to display this person's experiments, and than i get the error

GetExpDetails ERROR:Operator '=' is not defined for type 'DBNull' and 'Nothing'

When trying to run this code:

If dr("ExpDate") = vbNullString Then
   c.Controls.Add(New LiteralControl(" "))

Else

   arrExpDate = Split(dr("ExpDate"), "/")
   sExpDate = arrExpDate(0) & "/" & arrExpDate(1) & "/" & arrExpDate(2)
   c.Controls.Add(New LiteralControl(sExpDate))
End If

Any clues?

Im new to programming web sites, and this is a code im trying to fix.. Thank you


Try:

If IsDbNull(dr("ExpDate")) Then
   c.Controls.Add(New LiteralControl(" ")) 
Else      
   arrExpDate = Split(dr("ExpDate"), "/") 
   sExpDate = arrExpDate(0) & "/" & arrExpDate(1) & "/" & arrExpDate(2) 
   c.Controls.Add(New LiteralControl(sExpDate)) 
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜