简体   繁体   English

在mysql数据库的列中搜索空单元格并显示在datagridview上

[英]search for null cells in column of mysql database and display on the datagridview

My application requires to search the incompleted projects in our task management software. 我的应用程序需要在我们的任务管理软件中搜索未完成的项目。 And for that i am trying to implement a way i could read our MySQL database for incomplete projects and display them on the screen. 为此,我试图实现一种方法,可以读取不完整项目的MySQL数据库并将其显示在屏幕上。 The project will be incomplete if the particular cell is a "null value". 如果特定单元格为“空值”,则该项目将不完整。 The project is completed when the cell says "Completed". 当单元格显示“已完成”时,项目完成。 I am trying to search for all null values in a row and display them on to the DataGridView with visual basic C#. 我试图在一行中搜索所有空值,并使用Visual Basic C#将其显示在DataGridView上。 The code i tried is the following, unfortunately it didn't work: 我尝试过的代码如下,但不幸的是它没有用:

private void button4_Click(object sender, EventArgs e)
{
    DataView DV = new DataView(dt);
    DV.RowFilter = string.Format("BackSheetAssembled LIKE '%{0}%'", DBNull.Value );
    dataGridView1.DataSource = DV;
}

I tried the same method with substituting DBNull.Value with a text box and it works fine and search the database for those texts, but it doesn't work for a Null value. 我用文本框替换DBNull.Value尝试了相同的方法,它可以正常工作并在数据库中搜索这些文本,但是对于Null值不起作用。

尝试这个

DV.RowFilter = "Isnull(BackSheetAssembled,'') = ''";

DV.RowFilter = "BackSheetAssembled is null"; DV.RowFilter =“ BackSheetAssembled为空”;

Example: 例:

var table = new DataTable();
table.Columns.Add(new DataColumn("Id"));
table.Columns.Add(new DataColumn("Name"));
table.Rows.Add(new object[] { 123, "Name1" });
table.Rows.Add(new object[] { 234, "Name2"});
table.Rows.Add(new object[] { null, "Name3" });

var view = new DataView(table);
view.RowFilter = "Id is null";

for (int i = 0; i < view.Count; i++)
   Console.WriteLine(view[i][1].ToString());

Console.ReadLine();

Outputs: Name3 输出:Name3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM