PowerShell
using (SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ToString()))
{
using (SqlCommand myCmd = new SqlCommand())
{
myConn.Open();
myCmd.Connection = myConn;
myCmd.CommandText = "SELECT ID, MODEL, FAMILY FROM Table ORDER BY SORT_ORDER ASC";
myCmd.CommandType = System.Data.CommandType.Text;
using (SqlDataReader myReader = myCmd.ExecuteReader())
{
DropDownListRemote.DataSource = myReader;
DropDownListRemote.DataTextField = "MODEL";
DropDownListRemote.DataValueField = "ID";
DropDownListRemote.DataBind();
DropDownListRemote.Items.Insert(0, new ListItem("--Select a Model--", "0"));
DropDownListRemote.SelectedIndex = 0;
}
} }
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Suthish NairRank #93 · 22.6K pointsPosted Feb 7, 2011, 10:16 AM EST
List<int> i = new List<int>(); using (SqlDataReader myReader = myCmd.ExecuteReader()) { while (myReader.Read()) { i.Add = myReader[3]; i.Add = Convert.ToInt16(myReader[2]); DropDownListRemote.DataSource = myReader; DropDownListRemote.DataTextField = "MODEL"; DropDownListRemote.DataValueField = "ID"; DropDownListRemote.DataBind(); DropDownListRemote.Items.Insert(0, new ListItem("--Select a Model--", "0")); DropDownListRemote.SelectedIndex = 0; } }1 short reply
Suthish NairRank #93 · 22.6K pointsPosted Feb 8, 2011, 8:37 AM EST