Populating a Formview with the return value from a DataTable

Hello Experts,

I am pulling data from a SQL 2005 database and populate a formview. I am able to pass in my parameter value and when i breakpoint my code I see the results have the data I am looking for from the database. However when I try and set the datasource of the FormView I get an error of "Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource." I have included the database code I am running. Any direction you can give me would be great.

Jeff
*** Class calling DB ***

// Retrieve Auth Status information
    public static AuthStatusInfo GetAuthInfo(string sid)
    {
        // get a configured DbCommand object
        DbCommand comm = genericdataaccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "usp_GetAuthStatus";
        // create a new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@sid";
        param.Value = sid;
        param.DbType = DbType.String;
        comm.Parameters.Add(param);
        // obtain the results
        DataTable table = genericdataaccess.ExecuteSelectCommand(comm);
        DataRow authRow = table.Rows[0];
        // save the results into an AuthStatusInfo object
        AuthStatusInfo authstatus;
        authstatus.sid = authRow["SID"].ToString();
        authstatus.sid_description = authRow["SID Description"].ToString();
        authstatus.auth_enabled = bool.Parse(authRow["Auth Enabled"].ToString());
        authstatus.brownout = bool.Parse(authRow["Browned Out"].ToString());
        authstatus.notes = authRow["Notes"].ToString();
        // return the AuthInfo object
        return authstatus;
    }

*** Code behind on form ***

protected void asc_search_btn_Click(object sender, System.EventArgs e)
    {
        if (string.IsNullOrEmpty(asc_sid_search_txt.Text))
        {
            asc_error_lit.Text = "You must enter a valid SID to perform a search.";

            asc_sid_search_txt.Focus();
        }
        else
        {
            asc_search_pnl.Visible = false;
            asc_results_pnl.Visible = true;

            FormView1.DataSource = AuthStatus.GetAuthInfo(asc_sid_search_txt.Text);
            FormView1.DataBind();

            Button btn1 = (Button)FormView1.FindControl("asc_results_edit_btn");
            Button btn2 = (Button)FormView1.FindControl("asc_results_insert_btn");
        }
    }

Open in new window

woodjeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

drypzCommented:
Hi! You may change the type of GetAuthInfo into a List of AuthStatusInfo. You may include System.Collections.Generic in your namespace declarations. Something like
    public static List<AuthStatusInfo> GetAuthInfo(string sid)
    {
List<AuthStatusInfo> statusInfo = new List<AuthStatusInfo>();

        // get a configured DbCommand object
        DbCommand comm = genericdataaccess.CreateCommand();
        // set the stored procedure name
        comm.CommandText = "usp_GetAuthStatus";
        // create a new parameter
        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@sid";
        param.Value = sid;
        param.DbType = DbType.String;
        comm.Parameters.Add(param);
        // obtain the results
        DataTable table = genericdataaccess.ExecuteSelectCommand(comm);
        DataRow authRow = table.Rows[0];
        // save the results into an AuthStatusInfo object
        AuthStatusInfo authstatus;
        authstatus.sid = authRow["SID"].ToString();
        authstatus.sid_description = authRow["SID Description"].ToString();
        authstatus.auth_enabled = bool.Parse(authRow["Auth Enabled"].ToString());
        authstatus.brownout = bool.Parse(authRow["Browned Out"].ToString());
        authstatus.notes = authRow["Notes"].ToString();
        // return the AuthInfo object

statusInfo.Add(authstatus);
        return statusInfo;

    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.