Hey fellas,

I have a problem with my current code. I have a checklist that i want certain items to be selected bases of a sql query. here is the code:

public void PopulateCheckList(int Program_Id)
        {
            SqlDataReader myReader = null;
            String appConnectionString = "Data Source=csdb-wc-1p;DataBase=oparch_metrics_v2;User ID=ops_metrics_admin;Pwd=M3tr!c$@dm!n";
            SqlConnection myConnection = new SqlConnection(appConnectionString);
            String result;
            try
            {
                myConnection.Open();
                string sqlCommand = "Select AppID From CET_ScorecardProgramApplicationMapping WHERE Program_Id = @Pogram_Id";
                SqlCommand mycommand = new SqlCommand(sqlCommand, myConnection);
                mycommand.CommandType = CommandType.StoredProcedure;
                mycommand.Parameters.Add(new SqlParameter("@Program_Id", Program_Id));
                 
                myReader = mycommand.ExecuteReader();

                ListItem first = new ListItem();
   
                ddlContacts.Items.Add(first);

                while (myReader.Read())
                {
                    if()
                    
                    
                    applicationCheckList.Item[i].Selected =  true ;
                }
            }
            catch (SqlException ex)
            {
                result = ex.ToString();
            }
            finally
            {
                if (myConnection != null)
                {
                    myConnection.Close();
                }
                if (myReader != null)
                {
                    myReader.Close();
                }
            }
        }

im not sure what to put in the while(myRead.Read()) loop

if you guys could help me i would be very grateful

Something like this i think?

while (myReader.Read())
                {
                    foreach (ListItem item in applicationCheckList.Items)
                    {
                        if (applicationCheckList.Items.Value == myReader.GetString(0))
                         {
                             applicationCheckList.Items(0).selected = true;
                         }
                    }
                }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.