السلام عليكم ورحمة الله
الخطأ بهذا الكود بالتحديد
x = dr[0].ToString();
وهذا هو الكود بالكامل
string query = "select count from code where code = '"+TextBox1.Text+"'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr;
con.Open();
dr= cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
if (dr.HasRows)
{
while (dr.Read())
{
string x ="";
int y =0;
x = dr[0].ToString();
y = Convert.ToInt16(x);
if( y > 10)
{
Label2.Text = "لقد تخطيت الحد المسموج به";
}
}
}
else
{
Label2.Text = "كود خطأ";
}
con.Close();