风尘小剑 2019-06-10 18:34 采纳率: 0%
浏览 261

C# datagridview 查询代码哪里错了

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();

    }
  • 写回答

2条回答 默认 最新

  • threenewbee 2019-06-10 20:07
    关注

    调试输出下sql,是不是sql拼接错误,还有数据库连接错误。看丢出什么异常。你这代码一贴谁知道

    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛