数据库查询操作问题子查询最多能返回一个返回记录 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();
展开
 我来答
leon382
2010-08-11 · TA获得超过1064个赞
知道小有建树答主
回答量:1744
采纳率:0%
帮助的人:976万
展开全部
你带入条件
执行下你的 select BID from book where BName where 查询条件
看看 是否只有一条呢

你BID 是什么字段? 是否是想汇总呢
把他修改成下面这样看看
select sum(BID) from book where BName where 查询条件
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式