if (txt_SendAt.Text != null)
{
//string SendAt_date = txt_Respondby.Text;
DateTime Send_date = Convert.ToDateTime(txt_SendAt.Text);
param[15] = new MySqlParameter("@SendDate", MySqlDbType.DateTime);
param[15].Value = Send_date;
command.Parameters.AddWithValue("@SendDate", Send_date);
}
else
{
param[15] = new MySqlParameter("@SendDate", MySqlDbType.DateTime);
param[15].Value = now;
command.Parameters.AddWithValue("@SendDate", now);
}
Run Code Online (Sandbox Code Playgroud)
我有一个文本框,我从日历中选择日期和时间.当我将文本框留空时,它应该在else条件下执行语句,但它在if中执行语句.我哪里错了
如果我将其留空,我收到此错误字符串未被识别为有效的DateTime.
您正在测试文本框本身是否为null,而不是文本:
if (string.IsNullOrEmpty(txt_SendAt.Text) == false)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
172 次 |
| 最近记录: |