Zakir Ahamed

Zakir Ahamed

  • NA
  • 1.4k
  • 607.4k

Enumaration yielded no results

Jul 25 2017 2:49 AM
hi friends
 
i have prblm in datareader in result view i am gettin following error message:
 
 Enumaration yielded no results
 
the following code:
 
if (txtcategory.Text != " ")
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RetailTestConnection"].ConnectionString);
con.Open();
string query = String.Format("Select B.BrandId from Brand_Mst B JOIN Category_brand_Tbl cb on B.BrandId = cb.BrandId JOIN Category_Mst c on c.CategoryId = cb.CategoryId Where c.categoryname = '{0}'",txtcategory.Text);
SqlCommand cmd = new SqlCommand(query,con);
SqlDataReader dr = cmd.ExecuteReader();
string[] s = new string[] { };
while (dr.Read())
{
s = dr.ToString().Split(',');
}
int Length = s.Length;
for (int i = 0; i < Length; i++)
// for (int i = 0; i <= 1; i++)
{
string fetr = s[i];
for (int j = 0; j <= clbbrand.Items.Count - 1; j++)
{
if (clbbrand.Items[j].ToString() == s[i])
{
clbbrand.SetItemChecked(j, true);
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
 
 
if any one knows help  me how to getting data 

Answers (2)