如何检查,DataGridView中的空单元格的值? [英] How can I check the null cell value in the DataGridView?
本文介绍了如何检查,DataGridView中的空单元格的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何检查在C#中的DataGridView的空单元格的值?
我使用的DBNull
进行检查,但它不能正常工作。
任何人可以帮助我吗?
在code我现在拥有的是:
的String [] AR =新的字符串[dataGridView1.Columns.Count]
的for(int i = 0; I< dataGridView1.Columns.Count;我++)
{
如果(dataGridView1.Rows [0] .Cells [I]。价值!=的DBNull.Value)
{
如果(ⅰ!= 0)
{
芳[I] = dataGridView1.Rows [0] .Cells [I] .Value.ToString();
}
其他
{
芳[I] = dataGridView1.Rows [0] .Cells [I] .Value.ToString();
}
}
解决方案
您可以使用此
如果(!Convert.IsDBNull(dataGridView1.Rows [0] .Cells [I]。价值))
{
如果(ⅰ!= 0)
{
芳[I] = dataGridView1.Rows [0] .Cells [I] .Value.ToString();
}
其他
{
芳[I] = dataGridView1.Rows [0] .Cells [I] .Value.ToString();
}
}
How can I check the null cell value in a DataGridView in C#?
I've used DBNull
for checking, but it is not working.
Can anybody help me?
The code I currently have is:
string[] ar=new string[dataGridView1.Columns.Count];
for(int i=0;i<dataGridView1.Columns.Count;i++)
{
if (dataGridView1.Rows[0].Cells[i].Value != DBNull.Value)
{
if (i != 0)
{
ar[i] = dataGridView1.Rows[0].Cells[i].Value.ToString ();
}
else
{
ar[i] = dataGridView1.Rows[0].Cells[i].Value.ToString();
}
}
解决方案
you can use this
if(!Convert.IsDBNull(dataGridView1.Rows[0].Cells[i].Value))
{
if (i != 0)
{
ar[i] = dataGridView1.Rows[0].Cells[i].Value.ToString ();
}
else
{
ar[i] = dataGridView1.Rows[0].Cells[i].Value.ToString();
}
}
这篇关于如何检查,DataGridView中的空单元格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文