数据库查询操作问题子查询最多能返回一个返回记录 5
stringsql1="(BNum-(selectcount(*)frombookwhere";stringsql="selectBIDas图书编号,BNameas图书名...
string sql1 = "(BNum-(select count(*) from book where ";
string sql = "select BID as 图书编号,BName as 图书名,BWriter as 作者,BPublish as 出版社,BDate as 出版日期,BPrice as 价格," +
"BNum as 数量,type as 类型,BRemark as 备注,ISBN, ";
if (textID.Text.Trim() != "")
{
sql1 = sql1 + " BID= " + "'" + textID.Text.Trim() + "')) as 库存数量 ";
sql = sql + sql1 + "from book where BID= " + "'" + textID.Text.Trim() + "'";
}
else if (textName.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where BName='" + textName.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where BName= " + "'" + textName.Text + "'";
}
else if (textWriter.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where BWriter='" + textWriter.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where BWriter= " + "'" + textWriter.Text + "'";
}
else if (textBox1.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where ISBN='" + textBox1.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where ISBN= " + "'" + textBox1.Text + "'";
}
else
{
MessageBox.Show("请输入查询条件", "提示");
return;
}
oleConnection1.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(sql, oleConnection1);
DataSet ds = new DataSet();
ds.Clear();
adp.Fill(ds, "book");///子查询最多能返回一个返回记录
dataGrid1.DataSource = ds.Tables[0].DefaultView;
dataGrid1.CaptionText = "共有" + ds.Tables[0].Rows.Count + "条查询记录";
oleConnection1.Close(); 展开
string sql = "select BID as 图书编号,BName as 图书名,BWriter as 作者,BPublish as 出版社,BDate as 出版日期,BPrice as 价格," +
"BNum as 数量,type as 类型,BRemark as 备注,ISBN, ";
if (textID.Text.Trim() != "")
{
sql1 = sql1 + " BID= " + "'" + textID.Text.Trim() + "')) as 库存数量 ";
sql = sql + sql1 + "from book where BID= " + "'" + textID.Text.Trim() + "'";
}
else if (textName.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where BName='" + textName.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where BName= " + "'" + textName.Text + "'";
}
else if (textWriter.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where BWriter='" + textWriter.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where BWriter= " + "'" + textWriter.Text + "'";
}
else if (textBox1.Text.Trim() != "")
{
sql1 = sql1 + " BID=(select BID from book where ISBN='" + textBox1.Text + "'))) as 库存数量 ";
sql = sql + sql1 + "from book where ISBN= " + "'" + textBox1.Text + "'";
}
else
{
MessageBox.Show("请输入查询条件", "提示");
return;
}
oleConnection1.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(sql, oleConnection1);
DataSet ds = new DataSet();
ds.Clear();
adp.Fill(ds, "book");///子查询最多能返回一个返回记录
dataGrid1.DataSource = ds.Tables[0].DefaultView;
dataGrid1.CaptionText = "共有" + ds.Tables[0].Rows.Count + "条查询记录";
oleConnection1.Close(); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询