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 + "'");//执行登记编号条件和图书名称条件
} 展开
{
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 + "'");//执行登记编号条件和图书名称条件
} 展开
1个回答
展开全部
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)
说明查询不对,返回的表式空的
if (MyDataTable.Rows.Count > 0)
说明查询不对,返回的表式空的
更多追问追答
追问
那应该怎么改呢
追答
......没看到你怎么做查询的...不知道怎么改...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询