-1

I want to use the Row of the Datarow in my code. What my datarow has the value which comes from the stored procedure. See the code below

 public void SendMail()
    {
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
        {
            SqlCommand cmd = new SqlCommand("GET_INWARD_REMINDER_REPORT", conn);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            da.Fill(ds);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["UserEmail"].ToString() == "10000")
                {
                    string StrPriBody = "Dear " + dr.Rows[i]["UserName"].ToString() + ", <br /><br />  "+                         
                    "This is a test mail for reminder. " +

                    string StrPriBody = "Dear " + dr.Rows[i]["name"].ToString() + ", <br /><br /> " +        } } }

but I am unable to use its Rows.

I tried like this

string StrPriBody = "Dear " + dr.Rows[i]["UserName"].ToString() + ", <br /><br />  "+ 

but at Rows i am getting error as

system.data.datarow' does not contain a definition for 'rows'

So how to deal with this.

Also see the datarow screenshot

Datarow

Nad
  • 4,605
  • 11
  • 71
  • 160

3 Answers3

1
foreach (DataRow dr in ds.Tables[0].Rows)
{
    if (dr["UserEmail"].ToString() == "10000")
    {
        string StrPriBody = "Dear " + dr["UserName"].ToString() + ", <br /><br />  "+ "This is a test mail for reminder. " + string StrPriBody = "Dear " + dr["name"].ToString() + ", <br /><br /> " +  "";      
        } 
    }
}

Update:

dr.Rows isn't necessary as it gives you error.

Have a read on the following helpful links.

http://www.dotnetperls.com/datarow

https://msdn.microsoft.com/en-us/library/system.data.datarow(v=vs.110).aspx

woodykiddy
  • 6,074
  • 16
  • 59
  • 100
1
string StrPriBody = "Dear " + dr["UserName"].ToString() + ", <br /><br />  "+ 
Sami
  • 3,686
  • 4
  • 17
  • 28
1

DataRow doen't contain 'Rows' property so it give you error.

 foreach (DataRow dr in ds.Tables[0].Rows)
        {
            if (dr["UserEmail"].ToString() == "10000")
            {
                string StrPriBody = "Dear " + dr["UserName"].ToString() + ", <br /><br />  "+                         
                "This is a test mail for reminder. " +

                string StrPriBody = "Dear " + dr["name"].ToString() + ", <br /><br /> " +       
            }
         }
Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27