Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get data for drop down list 1

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
I would like to return my data from one function into another which will populate a drop down list. I was just testing this and am pretty sure that it has to do with the variable being passed into the getData function (see below in red), but I'm not seeing exactly where I'm going wrong. Looking up the error message on the net hasn't helped, either... It's probably something very simple but any help would be appreciated. Thanks.

The error message is as follows: "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource." I'm using VS 2005, C#.

Code:
protected void Page_Load(object sender, EventArgs e)
    {
        FillState();
    }

    public SqlDataAdapter getData([COLOR=red]string strSQL[/color])
    {
        string cnString = ConfigurationManager.ConnectionStrings["StrConn"].ToString();
        SqlConnection conn = new SqlConnection(cnString);
        conn.Open();
        SqlCommand cmd = new SqlCommand(strSQL, conn);

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return da;
    }

    private void FillState()
    {
        ddlState.DataSource = getData("EXEC SP_GET_STATE");
        ddlState.DataTextField = "st_txt";
        ddlState.DataValueField = "st_txt";
        ddlState.DataBind();
        
    }

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
You can't bind the ddl to a dataadapter, you have to bind it to a dataset or datatable or something that impliments "IListSource, IEnumerable, or IDataSource" as your error states.
So try returning the dataset or datatable from your getData() function, not the dataadapter
 
Ah, ok... I'll try that and see what happens. I'll let you know (though it may be later this weekend or Monday depending on how things go). Thanks!

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Connectivity issues at home this weekend, so couldn't test until this morning. I made the change you suggested and it works as it should. Thanks!

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top