SqlCommand cmd2 = new SqlCommand("select img.img from img inner join cars on img.carid= cars.carid where cars.carnum = '"+crn+"'", con);
SqlDataReader reader = cmd2.ExecuteReader();
while (reader.Read())
{
Label2.Text = reader.GetString(0);
}
string car = Label2.Text;
if (car == null)
{
string qry1 = "insert into img(img, carid)" + " values ('noimg.jpg', (select carid from cars where carnum ='" + crn + "'";
SqlCommand cmd3 = new SqlCommand(qry1, con);
cmd3.ExecuteNonQuery();
}
int ab = cmd1.ExecuteNonQuery();
if (ab != null)
{
string myStringVariable = string.Empty;
myStringVariable = "Your Car data has been entered";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
}
我想要做的是,如果圖像表的select查詢通過null,然後在數據庫中插入默認圖像..但如果(車==空)部分根本沒有執行。它會跳過if部分。 WWhat要做什麼?'if'部分沒有執行..在c上工作#
你的車串永遠不能爲null。你必須檢查它是否爲空或'「」' – RandomStranger
其空。我通過調試器檢查它 – Samsam
'string car = Label2.Text;'<這意味着它永遠不會爲空,因爲你正在分配一個值。檢查它是空的還是''「' – RandomStranger