我想知道如何检查字段是否包含空值并将其替换为文本 N/A 或不显示该字段。但是如果字段包含 null 我不希望代码中断,我希望它继续运行,直到所有字段都填充了一个值。
C# 代码
using (var connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT FirstName, LastName, Date FROM EOI WHERE (FormID = '13')";
connection.Open();
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
Label1.Text = reader["FirstName"].ToString();
Label2.Text = reader["LastName"].ToString();
DateTime Text = Convert.ToDateTime(reader["Date"]);
Label3.Text = Text.ToString("d");
}
}
}