1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public CascadingDropDownNameValue[] GetCategories(string knownCategoryValues, string category)
{
//Create sql connection and sql command
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "Select * from Categorie";
//Create dataadapter and fill the dataset
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
DataSet objDs = new DataSet();
dAdapter.Fill(objDs);
con.Close();
//create list and add items in it
//by looping through dataset table
List<CascadingDropDownNameValue> categorieNames
= new List<CascadingDropDownNameValue>();
foreach (DataRow dRow in objDs.Tables[0].Rows)
{
string CategorieID = dRow["idCategorie"].ToString();
string CategorieName = dRow["Categorie"].ToString();
categorieNames.Add(new CascadingDropDownNameValue
(CategorieName, CategorieID));
}
return categorieNames.ToArray();
} |
Partager