G
Guest
I know this must be something very simple, since none of the online samples
for populating a dropdownlist from a sql database indicate this is difficult
with asp.net... but I'm still not getting what I'm hoping for.
Basically, I can attach to my database, query results and if I use a
datagrid, I can see all of my columns/rows. What I want to do now is perform
the same query and display only one of my columns in a dropdownlist, so that
I can later use the list to perform specialized queries.
My query works, but my display is showing "System.Data.Common.DbDataRecord"
instead of the row values in my database.
I know I must be missing something trivial, a using statement, or a cast of
some kind or a property setting, but I can't locate what I'm not doing
correctly?
Can anyone shed a little light for me?
Thanks,
Sherwood
My code below:
<aspropDownList id="DropDownChoice" runat="server" ></aspropDownList>
if (!IsPostBack)
{
SqlCommand myCommand = new SqlCommand("select distinct myColumn from
myTable", myConnection);
myConnection.Open();
DropDownChoice.DataSource=
myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DropDownChoice.DataBind();
DropDownChoice.Items.Insert(0, new ListItem("-- Choose --"));
}
for populating a dropdownlist from a sql database indicate this is difficult
with asp.net... but I'm still not getting what I'm hoping for.
Basically, I can attach to my database, query results and if I use a
datagrid, I can see all of my columns/rows. What I want to do now is perform
the same query and display only one of my columns in a dropdownlist, so that
I can later use the list to perform specialized queries.
My query works, but my display is showing "System.Data.Common.DbDataRecord"
instead of the row values in my database.
I know I must be missing something trivial, a using statement, or a cast of
some kind or a property setting, but I can't locate what I'm not doing
correctly?
Can anyone shed a little light for me?
Thanks,
Sherwood
My code below:
<aspropDownList id="DropDownChoice" runat="server" ></aspropDownList>
if (!IsPostBack)
{
SqlCommand myCommand = new SqlCommand("select distinct myColumn from
myTable", myConnection);
myConnection.Open();
DropDownChoice.DataSource=
myCommand.ExecuteReader(CommandBehavior.CloseConnection);
DropDownChoice.DataBind();
DropDownChoice.Items.Insert(0, new ListItem("-- Choose --"));
}