本文介绍了如何使用int ID为null的条件过滤数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有gridview:

I have gridview:

GridViewName.DataSource = table;



表值:


table values:

string myConnection = ConfigurationManager.ConnectionStrings["vizitka"].ToString();
string Query_sel = MySqlString;
MySqlConnection conDataBase = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase_sel = new MySqlCommand(Query_sel, conDataBase);
  try
  {
     MySqlDataAdapter sda = new MySqlDataAdapter();
     sda.SelectCommand = cmdDataBase_sel;
     DataTable dbdataset = new DataTable();
     sda.Fill(dbdataset);
     BindingSource bSource = new BindingSource();
     bSource.DataSource = dbdataset;
     TableName.DataSource = bSource;
     sda.Update(dbdataset);
   }
     catch (Exception ex)
     {
        MessageBox.Show(ex.Message);
     }



我得到的价值观:

[]



然后,我正在添加新行到表:


I'm getting Values:
https://i.stack.imgur.com/G561j.jpg[^]

then, I'm adding new row to table:

DataRow newRow = table.NewRow();
table.Rows.Add(newRow);



并获取带有空单元格的值(ID也为空,对我有好处):

[]

然后:


and getting values with empty cells (also ID is empty and it's good for me):
https://i.stack.imgur.com/quGck.jpg>[^]
then:

GridViewName.DataSource = table;



一切都很好,但随后如果我想从表中删除这个新创建的行,我不能。我正在尝试过滤并再次绑定GridViewName。



我尝试过:




all is good, but then if I want to delete from table this new created row, I cannot. I'm trying to filter and bind again GridViewName.

What I have tried:

DataView view = new DataView(table);
view.RowFilter = "CONVERT(id, System.String) = null or CONVERT(id, System.String) = ''";
Console.WriteLine(view);



但是我得到空表。为什么?????


but I'm getting empty table. why?????

推荐答案

view.RowFilter = "ID IS NULL";


这篇关于如何使用int ID为null的条件过滤数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 22:13