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
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Zakir AhamedPosted Jul 25, 2017, 9:10 AM
{
try
{
indexRow = e.RowIndex;
DataGridViewRow row = GvCategory.Rows[indexRow];
txtcategory.Text = row.Cells[1].Value.ToString();
//txtcategory.ReadOnly = true;
btncategory.Text = "Update";
rbyes.Checked = true;
if (txtcategory.Text != String.Empty)
{
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 = @Name");
//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 = ' " + txtcategory.Text + " ' ");
SqlCommand cmd = new SqlCommand(query,con);
cmd.Parameters.Add(new SqlParameter("Name", txtcategory.Text));
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());
}
}
Manas MohapatraPosted Jul 25, 2017, 7:21 AM