如何检查行值的ds为null [英] How to check ds of row value is null
问题描述
如果(ds.Table [0] .Rows [6]!== Null)
{
lblauthorititesname16.Text = ds.Tables [0] .Rows [6] [authoritites_Name]。ToString();
lblauthorititesdesig17.Text = ds.Tables [0] .Rows [6] [authoritites_Designation]。ToString();
lblauthorititescontact18.Text = ds.Tables [0] .Rows [6] [authoritites_Contact]。ToString();
}
If(ds。表[0] .Rows [6]!== Null)
{
lblauthorititesname19.Text = ds.Tables [0] .Rows [7] [authoritites_Name ] .ToString();
lblauthorititesdesig20.Text = ds.Tables [0] .Rows [7] [authoritites_Designation]。ToString();
lblauthorititescontact21.Text = ds.Tables [0] .Rows [7] [authoritites_Contact]。ToString();
}
我的尝试:
请帮助我如何检查我想要使用ds的行值然后进入if条件
If(ds.Table[0].Rows[6]!== Null)
{
lblauthorititesname16.Text = ds.Tables[0].Rows[6]["authoritites_Name"].ToString();
lblauthorititesdesig17.Text = ds.Tables[0].Rows[6]["authoritites_Designation"].ToString();
lblauthorititescontact18.Text = ds.Tables[0].Rows[6]["authoritites_Contact"].ToString();
}
If(ds.Table[0].Rows[6]!== Null)
{
lblauthorititesname19.Text = ds.Tables[0].Rows[7]["authoritites_Name"].ToString();
lblauthorititesdesig20.Text = ds.Tables[0].Rows[7]["authoritites_Designation"].ToString();
lblauthorititescontact21.Text = ds.Tables[0].Rows[7]["authoritites_Contact"].ToString();
}
What I have tried:
Please help me how to check i want to use ds of row value then goes in to if condition
推荐答案
你可以试试这个条件:
You can try this condition :
if (DataSet.Tables(0).Rows(0).Item["FieldName"] == DBNull.Value){
//null condition
}
else{
//not null condition
}
if(ds.Tables[0].Rows.Count>=7){ // ensure that row 6 exists // zero based index
string[] columnsToCheck = new string[]{"authoritites_Name","authoritites_Designation","authoritites_Contact"};
bool isAllColumnsNull = columnsToCheck.All(k=> string.IsNullOrEmpty( ds.Tables[0].Rows[6][k]+""));
if(!isAllColumnsNull){
// your code.
}
}
这篇关于如何检查行值的ds为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!