我正在尝试向数据库服务器,人员ID,他参与的实验以及实验日期添加一些信息。
这是我的代码:
SQLConnection1.ConnectionString = MyConn
Dim drNewRow As DataRow = DtsLabSystem1.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
我的问题是,当重定向到SubjectDetails.aspx时,我尝试显示此人的实验,而不是我收到错误
GetExpDetails ERROR:没有为类型'DBNull'和'Nothing'定义运算符'='
尝试运行此代码时:
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
任何线索?
我是编程网站的新手,这是一个试图修复的代码.. 谢谢
答案 0 :(得分:0)
尝试:
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