2016-07-06 118 views
0

我有一个像下面如何使用

结果集的dataset数据集的栏目[![数据集] [1] [1]

现在我想添加IF条件检查像低于

if(dataset rows(Usermail) == 10000){then go ahead} 

这是我的代码。

DataSet ds = new DataSet(); 
     using (SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString())) 
     { 
      SqlCommand sqlComm = new SqlCommand("GET_INWARD_REMINDER_REPORT", conn); 
      sqlComm.CommandType = CommandType.StoredProcedure; 
      SqlDataAdapter da = new SqlDataAdapter(); 
      da.SelectCommand = sqlComm; 
      da.Fill(ds); 

      if(DataSet rowchecking) 
      { 

      } 
     } 

所以我的问题,如何检查和比较数据集列。

+0

您需要访问行中的字段,获取其值,而不是列。 – Alex

+0

@Alex:只有我想知道,如何实现。 – BNN

回答

1

你可以像下面:

int First = Convert.ToInt32(ds.Tables[0].Rows[0]["columnName1"].ToString()); 
string Second = ds.Tables[0].Rows[0]["columnName2"].ToString(); 

因此,对于你的情况下,可以如:

foreach (DataRow dr in ds.Tables[0].Rows) 
{ 
    if(dr["UserEmail"].ToString() == "10000") 
    { 
     //do something; 
    }   
} 
+0

但它只有一个邮件,我们可以循环吗? – BNN

+0

请检查更新。 –

+0

这是工作。谢谢Rahul – BNN

1

可以使用foreach循环行和使用DataRow.Field获得的电子邮件:

foreach(DataRow row in ds.Tables[0].Rows) 
{ 
    if(row.Field<string>("UserEmail") == "10000") 
     continue; // or revert it and do something if UserEmail != "1000" 
} 
+0

错误为** system.data.dataset'在'Table'中不包含'tables'的定义** – BNN

+0

@NK:修正了它,它的'Tables'不是'Table' –

+0

是的,也在行'行.Field (“UserEmail”))'我得到错误,因为**不能隐式地将字符串转换为bool – BNN

0

填充数据集之后。

if (ds.Tables[0].Rows.Count > 0) 
{ 
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
    { 
    if(ds.Tables[0].Rows[i]["UserEmail"].ToString() == "10000") 
    { 
    //do something; 
    } 
    } 
}