我在运行项目时遇到错误。我想,如果TextBox1的是empty.My代码来创建一个if语句是这样的:不能将类型'字符串'转换为'bool'
SqlCommand cmd = new SqlCommand(" DELETE from Records WHERE ([Student ID]='" + textBox1.Text + "')", con);
MessageBox.Show("Data Deleted!", "Information ... ", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
textBox1.Text = " ";
if (textBox1.Text = " ")
{
MessageBox.Show("Please enter Student ID", "Delete Failed",MessageBoxButtons.OK,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1);
}
cmd.ExecuteNonQuery();
con.Close();
错误是texbox1.Text =“”
你是不是指'textBox1.Text ==“”'?使用'=='你**比较**,使用'='你**指定**。 – user2674389
尝试使用string.IsNullOrWhiteSpace() – Miller
即使没有编译错误,当您自己分配文本时,代码完全没有意义。 –