What am I missing here from this function/control?

  • Thread starter Microsoft News Group
  • Start date
M

Microsoft News Group

I am populating a dropdown list from a DB Table and cannot get the list to
populate! Can anyone see what I am missing? I am telling the dropdownlist to
use 2 fields from the record set, then from the codebehind I am pushing the
dataset to the dropdownlist.

Thoughts?

<asp:DropDownList id="ivState" runat="server" DataTextField="State"
DataValueField="ST_Abbrev"></Asp:DropDownList>

private void loadStates()
{

OleDbConnection stconn = null;

OleDbDataReader streader = null;


try

{

string indexTable = "tblStates";


stconn = new OleDbConnection(Configuration.pdsConnectionString);

stconn.Open();

string stquery = "SELECT State, ST_Abbrev, Meridian_Name, N_Max, S_Max,
E_Max, W_Max FROM " + indexTable;


OleDbCommand cmd = new OleDbCommand(stquery, stconn);


streader = cmd.ExecuteReader();


ivState.DataSource = streader;

ivState.DataBind();

}

catch (Exception e)

{

#region ErrorCode

Response.Write("<BR>");

Response.Write(e.Message);

Response.End();

#endregion

}

finally

{

if (streader != null) streader.Close();

if (stconn != null) stconn.Close();

}

}
 
M

Marina

Are you telling the dropdown which column to use for the text and which for
the value?

Your query has 7 columns, you only need 2 at most, one for each of the
settings I mentioned above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top