我在book1
表中有2列book2
和Borrowes
到,但是有些时候用户借用了这本书,有些时候没有,所以我需要删除没有借用任何书的用户( book1
或book2
)。我得到了每一次True的价值。让我知道我能做什么谢谢。
我尝试过了...
con.Open();
bool readerHasRows = false;
string brid = txtBr_id.Text;
String syntax = "SELECT book1, book2 FROM Borrowes WHERE brId = @brid";
using (SqlCommand cmd = new SqlCommand(syntax, con))
{
cmd.Parameters.AddWithValue("@brid", txtBr_id.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
readerHasRows = (!reader[0].IsDBNull);
}
}
con.Close();
if (readerHasRows == true)
{
MessageBox.Show("This borrower has borrowed the book please collect the book first.");
}
答案 0 :(得分:0)
如果您将没有借书的用户的book1和book2设置为null:
con.Open();
bool readerHasRows = false;
string brid = txtBr_id.Text;
String syntax = "SELECT book1, book2 FROM Borrowes WHERE brId = @brid AND (book1 IS NOT NULL OR book2 IS NOT NULL)";
using (SqlCommand cmd = new SqlCommand(syntax, con))
{
cmd.Parameters.AddWithValue("@brid", txtBr_id.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
readerHasRows = reader.read();
}
}
con.Close();
if (readerHasRows == true)
{
MessageBox.Show("This borrower has borrowed the book please collect the book first.");
}