我有一个代码如下...
if(txtEditName.Text.Trim() == "" || txtEditAddress.Text.Trim() == "")
{
lblBError.Enabled = true;
lblBError.Visible = true;
lblBError.Text = "Please provide the required field.";
return;
}
else
{
if(txtControl.Text.Trim() == "")
{
if(DropDownClient.Enabled)
{
if(DropDownClient.SelectedItem.Value == "select")
{
lblBError.Enabled = true;
lblBError.Visible = true;
lblBError.Text = "Please select Client.";
return;
}
}
else
{
if(lblClientName.Text.Trim() != "")
{
sql = @"INSERT INTO [BRANCH] (bname,baddress,bcity,bstate,bpostcode,bphone,bfax,bemail,clientID)
VALUES (@bname,@baddress,@bcity,@bstate,@bpostcode,@bphone,@bfax,@bemail,(SELECT clientID FROM [CLIENT] WHERE cname='" + lblClientName.Text + "'))";
}
else
{
sql = @"INSERT INTO [BRANCH] (bname,baddress,bcity,bstate,bpostcode,bphone,bfax,bemail,clientID)
VALUES (@bname,@baddress,@bcity,@bstate,@bpostcode,@bphone,@bfax,@bemail," + DropDownClient.SelectedItem.Value + ")";
}
}
}
else
{
sql = @"INSERT INTO [BRANCH] (bname,baddress,bcity,bstate,bpostcode,bphone,bfax,bemail,clientID)
VALUES (@bname,@baddress,@bcity,@bstate,@bpostcode,@bphone,@bfax,@bemail," + Convert.ToInt32(txtControl.Text.Trim()) + " )";
// SqlCommand cmd = new SqlCommand(sql, connection);
}
}
我遇到的问题是,代码的某些部分没有执行。当我运行时,它忽略了 else 部分
if(lblClientName.Text.Trim() != "")
{
}
else
{
sql = @"INSERT INTO [BRANCH] (bname,baddress,bcity,bstate,bpostcode,bphone,bfax,bemail,clientID)
VALUES (@bname,@baddress,@bcity,@bstate,@bpostcode,@bphone,@bfax,@bemail," + DropDownClient.SelectedItem.Value + ")";
}
它为 else 部分跳转 sql =" " 并传递 sql ass 空字符串。我不确定为什么会这样?我检查了一切,一切似乎都很好。请有人指出代码有什么问题?