我想知道是否有人可以帮助我。我对编程和开发非常陌生(因此,如果这是一个愚蠢的问题,我深表歉意),但我非常坚持我目前正在从事的项目。
我正在编写一个 WinForms 应用程序,该应用程序每天运行一次以从数据库中检索信息。由此,如果满足特定标准,它将自动向建筑物中的个人发送电子邮件。消息正文将包含带入数据网格的各种详细信息。
目前,我的应用程序在尝试将详细信息传输到负责生成电子邮件的子程序时崩溃(因为某些变量返回为“Null”,因此无法转换为字符串)。我正在尝试实现一个 If 语句,如果它返回为 Null,则将一个字符串分配给变量,如下所示:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles RunTimer.Tick
years = My.Settings.Years.Split(",")
If TimeOfDay = "09:00:00" Then
Using cn As New SqlClient.SqlConnection
cn.ConnectionString = constr
cn.Open()
SQLstr = "long SQL string that works as have run it in WinSQL"
Using command As New SqlClient.SqlCommand(SQLstr, cn)
command.CommandTimeout = 0
command.CommandText = SQLstr
Using drd As SqlClient.SqlDataReader = command.ExecuteReader
While drd.Read
If Not drd("Joined Date") Is DBNull.Value Then
Dim memberyears As Integer = DateDiff(DateInterval.Year, drd("Joined Date"), Now)
Dim element As Integer
For element = 0 To years.GetUpperBound(0)
If years(element) = memberyears Then
Label1.Text = "Sending email"
End If
If Not drd("City") Is DBNull.Value Then
drd("City") = "Bleh"
End If
SendEmail(years(element), drd("Shop Name"), drd("Contact Name"), drd("Shop ID"), drd("Business Name"), drd("Address 1"), drd("Address 2"), drd("Address 3"), drd("District"), drd("City"), drd("County"), drd("Shop Postal Code"), drd("ASM"))
Next
End If
End While
End Using
End Using
End Using
Else
Label1.Text = "Skipped"
Exit Sub
End If
End Sub
If
我正在处理的声明是这样的:
If Not drd("City") Is DBNull.Value Then
drd("City") = "Bleh"
End If
但是它只是返回,因为属性“项目”是只读的。任何帮助将不胜感激。