c# 中listview显示数据库表的内容问题

privatevoidbutton1_Click(objectsender,EventArgse){DataTableMyDataTable=newDataTable()... private void button1_Click(object sender, EventArgs e)
{
DataTable MyDataTable = new DataTable();
if (tb_reg_no.Text.Trim() != "" || tb_book_name.Text.Trim() != "" || tb_book_author.Text.Trim() != "")
{
lsv_lessbook_info.Items.Clear();
MyDataTable = BU_xf.Check_LessBook_no_Name_author(tb_reg_no.Text.Trim(), tb_book_name.Text.Trim(), tb_book_author.Text.Trim());
if (MyDataTable.Rows.Count > 0)
{
foreach (DataRow MyDataRow in MyDataTable.Rows)
{
ListViewItem MyListViewItem = new ListViewItem();
MyListViewItem.Text = MyDataRow["reg_no"].ToString();
MyListViewItem.SubItems.Add(MyDataRow["book_name"].ToString());
MyListViewItem.SubItems.Add(MyDataRow["book_author"].ToString());
MyListViewItem.SubItems.Add(MyDataRow["reg_datetime"].ToString());
MyListViewItem.SubItems.Add(MyDataRow["book_explain"].ToString());
MyListViewItem.SubItems.Add(MyDataRow["admin_name"].ToString());
this.lsv_lessbook_info.Items.Add(MyListViewItem);
}

}
else
{
ListViewItem MyListViewItem = new ListViewItem();
MyListViewItem.Text = "没有数据";
MyListViewItem.SubItems.Add("没有数据");
MyListViewItem.SubItems.Add("没有数据");
MyListViewItem.SubItems.Add("没有数据");
MyListViewItem.SubItems.Add("没有数据");
MyListViewItem.SubItems.Add("没有数据");
lsv_lessbook_info.Items.Add(MyListViewItem);
}

}
else
{
MessageBox.Show("请填写查询条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}

按查询按钮后 listview中显示的全是“没有数据”,为什么呢?
if (reg_no.Length != 0 && Book_name.Length == 0 && book_author.Length == 0)
{
str.Append("and reg_no='" + reg_no + "' ");//执行登记编号条件
}
if (reg_no.Length == 0 && Book_name.Length != 0 && book_author.Length == 0)
{
str.Append("and Book_name='" + Book_name + "' ");//执行图书名称条件
}
if (reg_no.Length == 0 && Book_name.Length == 0 && book_author.Length != 0)
{
str.Append("and book_author='" + book_author + "'");//执行作者条件
}
if (reg_no.Length != 0 && Book_name.Length != 0 && book_author.Length == 0)
{
str.Append("and reg_no='" + reg_no + "' and Book_name='" + Book_name + "'");//执行登记编号条件和图书名称条件
}
展开
 我来答
vwenye
2011-06-01 · TA获得超过4984个赞
知道大有可为答主
回答量:1510
采纳率:0%
帮助的人:793万
展开全部
MyDataTable = BU_xf.Check_LessBook_no_Name_author(tb_reg_no.Text.Trim(), tb_book_name.Text.Trim(), tb_book_author.Text.Trim());
if (MyDataTable.Rows.Count > 0)
说明查询不对,返回的表式空的
更多追问追答
追问
那应该怎么改呢
追答
......没看到你怎么做查询的...不知道怎么改...
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式