Problem binding to DropDownList, "The IListSource does not contain any data sources"

Hi,
I'm attempting to use a data reader to load data from a single table, tblCountry, with two columns, countryNo (the Key) and countryName, into a DropDownList box. Here's the code:

protected System.Data.SqlClient.SqlConnection conn;
protected System.Data.SqlClient.SqlDataReader drCountry;
privatevoid Page_Load(object sender, System.EventArgs e)
{
string SQL = "SELECT * FROM tblCountry";
SqlConnection conn =new SqlConnection("Server=(local);Database=YLCdbSQL;Integrated Security=SSPI");
SqlCommand countryLoad =new SqlCommand (SQL, conn);
SqlDataReader drCountry =null;
try
{
conn.Open();
drCountry = countryLoad.ExecuteReader();

countryDropLst.DataSource = drCountry;
countryDropLst.DataMember = "countryName";
countryDropLst.DataTextField = "countryName";
countryDropLst.DataValueField = "countryNo";
countryDropLst.DataBind();
}
finally
{
drCountry.Close();
conn.Close();
}
}


But when I run it I get the error "The IListSource does not contain any data sources",and the DataBind line is highlighted.
I have checked the table using Enterprise Manager, it exists and has numerous entries in both columns.
Any idea what the problem might be?
Thanks.
[1823 byte] By [Assimalyst] at [2007-12-16]
# 1
My idea is that you are actually declaring two SqlDataReaders. The one is at the beginning:

protected System.Data.SqlClient.SqlDataReader drCountry;

The second is inside your Page_Load():

SqlDataReader drCountry = null;

I'm not sure this will help, but I would started with refraining such a repetition.

Best regards,
Eugene.

EugeneDorofeyev at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified