HEEN
HEEN

Reputation: 4727

How to use the Columns of dataset

I have a result set of dataset like below

[![Dataset][1]][1]

Now I want to add the IF condition for checking like below

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

this is my code.

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)
            {

            }
        }

So my issue, how to check and compare dataset columns.

Upvotes: 0

Views: 63

Answers (3)

Kuldip Rana
Kuldip Rana

Reputation: 131

After Fill dataset.

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;
    }
  }
}

Upvotes: 0

Rahul Hendawe
Rahul Hendawe

Reputation: 912

You can do it like below:

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

So for your case it can be like:

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

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460340

You can use a foreach to loop the rows and use DataRow.Field to get the email:

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

Upvotes: 1

Related Questions