Value cannot be null.Parameter name: key when databind in ASP.NET
- by Yongwei Xing
Hi all
I am triing to bind the data to a listbox from sql server then got the error "Value cannot be null.Parameter name: key"
sqlCommand = "SELECT [Country] FROM [tbl_LookupCountry] where [Country] IS NOT NULL";
SqlConnection sqlConCountry = new SqlConnection(connectString);
SqlCommand sqlCommCountry = new SqlCommand();
sqlCommCountry.Connection = sqlConCountry;
sqlCommCountry.CommandType = System.Data.CommandType.Text;
sqlCommCountry.CommandText = sqlCommand;
sqlCommCountry.CommandTimeout = 300;
sqlConCountry.Open();
reader = sqlCommCountry.ExecuteReader();
ddlCountry.DataSource = reader;
ddlCountry.DataBind();
sqlConCountry.Close();
Does anyone meet this problem before?