1
Reply

SQL Select query of more than one value of a same Attribute

Sayed Hassan

Sayed Hassan

Jul 20 2013 11:25 AM
1.3k
I have a Sql Database with many attributes. From there i want to take all the value of question attribute in an array named getQuestion Here Is my code


  vcon.Open();
            SqlCommand cmd = new SqlCommand("select question from examQuestion where tchId='123'", vcon);
            SqlDataReader dr = cmd.ExecuteReader();
            String[] getQuestion = { "" };
            int i = 0;
 
            while (dr.Read())
            { 
                getQuestion[i] = dr.GetString(0);
                i++;
            }
            vcon.Close();

It is fine when database contain single value, But when database has more then one value it provide an Error "Index was outside the bounds of the array". What is the problem? Please Help me. I am very new at ASP.Net.


Answers (1)