private void button13_Click(object sender, EventArgs e)
{
string sql1 = "(BNum-(select count(*) from bookOut where ";
string sql = "select BID as 书号,BName as 书名,BWriter as 作者,BPublish as 出版社,BDate as 出版日期,BPrice as 价格," + "BNum as 数量,type as 类型,BRemark as 备注, ";
if (txtBID.Text.Trim() != "")
{
sql1 = sql1 + " BID= " + "'" + txtBID.Text.Trim() + "')) as 库存数量";
sql = sql + sql1 + "from book where BID= " + "'" + txtBID.Text.Trim() + "'";
}
else if (txtBName.Text.Trim() != "")
{
sql1 = sql1 + "BID=(select BID from book where BName ='" + txtBName.Text + "'))) as 库存数量";
sql = sql + sql1 + "from book where BName= " + "'" + txtBName.Text + "'";
}
else if (txtBWriter.Text.Trim() != "")
{
sql1 = sql1 + "BID=(select BID from book where BWriter='" + txtBWriter.Text + "'))) as 库存数量";
sql = sql + sql1 + "from book where BWriter=" + "'" + txtBWriter.Text + "'";
}
else
{
MessageBox.Show("清输入正确查询条件", "提醒");
return;
}
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ds.Clear();
adp.Fill(ds, "book");
dataGridView4.DataSource = ds.Tables[0].DefaultView;
conn.Close();
}