私は以下のようなコードを持っています...
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 の空の文字列を渡します。なぜこれが起こるのかわかりませんか?私はすべてをチェックし、すべて問題ないようです。コードの問題点を教えてください。