i have problems filling my checkboxlist from a sql in c#. The list is empty when it have been loaded.
I know it would probably be easier with a connection to web.config, but i have decieded not to have web.config in this project. It would be helpfull if anyone could see what i have done wrong.
This is my code:
string connetionString = "Data Source=[DATA-SOURCE];Initial Catalog=[CATALOG];User ID=[USER-ID];Password=[PASSWORD]";
SqlConnection cnn = new SqlConnection(connetionString);
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT ModuleID, ModuleName, InternalName, Active FROM dbo.Zodiac_System_Modules WHERE Active = 1 ORDER BY ModuleName ASC";
cmd.Connection = cnn;
cnn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
ListItem item = new ListItem();
item.Text = sdr["ModuleName"].ToString();
item.Value = sdr["InternalName"].ToString();
chkModules.Items.Add(item);
}
}
cnn.Close();
}
You Are Missing CommandType This: