locked
Comparing textfield data with column data in a database table RRS feed

  • Question

  • User-791160327 posted

    i m giving my code can any one help me where is i m wrong. this code is checking only first rows data. not 2nd.

    bool result1 = true;
                        ModuleEntity objModuleEntity = new ModuleEntity();
                        objModuleEntity.ModuleName = txtModuleName.Text;
                        objModuleEntity.Departmen_ID =Convert.ToInt32(ddlDepartment.SelectedValue);
                        objModuleEntity.AddedBy = int.Parse(Session["UserID"].ToString());
                        DataTable dt = ModuleBLL.SelectModuleforsave(objModuleEntity);
                        if (dt.Rows.Count > 0)
                        {
                            DataRow dr = dt.Rows[0];

                            for (int i = 0; i< dt.Rows.Count; i++)
                            {
                                if (txtModuleName.Text == dr[1].ToString())
                                {
                                    result1 = false;
                                }
                            }
                        }

    thank u in advance

    Saturday, September 3, 2011 1:25 AM

Answers

  • User-68639941 posted

      if (dt.Rows.Count > 0)
                        {

                            for (int i = 0; i< dt.Rows.Count; i++)
                            {
                                     DataRow dr = dt.Rows[i];   // use i   while iterating re-assign DataRow to dr

                                if (txtModuleName.Text == dr[1].ToString())
                                {
                                    result1 = false;
                                }
                            }
                        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:29 AM
  • User896700311 posted

    Hi,

    try

    DataRow dr = dt.Rows[0];
    foreach (object c in dr.ItemArray) 
    {
         if (c.ToString() == txtModuleName.Text) 
         {
    	result1 = false;
         }
    }

    Any doubt, post your comment.

    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:35 AM
  • User-791160327 posted

    this is very helpful. thank u very much karthicks and Segundo .

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:44 AM

All replies

  • User-68639941 posted

      if (dt.Rows.Count > 0)
                        {

                            for (int i = 0; i< dt.Rows.Count; i++)
                            {
                                     DataRow dr = dt.Rows[i];   // use i   while iterating re-assign DataRow to dr

                                if (txtModuleName.Text == dr[1].ToString())
                                {
                                    result1 = false;
                                }
                            }
                        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:29 AM
  • User896700311 posted

    Hi,

    try

    DataRow dr = dt.Rows[0];
    foreach (object c in dr.ItemArray) 
    {
         if (c.ToString() == txtModuleName.Text) 
         {
    	result1 = false;
         }
    }

    Any doubt, post your comment.

    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:35 AM
  • User-791160327 posted

    this is very helpful. thank u very much karthicks and Segundo .

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 3, 2011 1:44 AM