Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:56:51+00:00 2026-05-27T01:56:51+00:00

Databinding private DataSet BindGridView(List<int> userids) { DataSet ds = new DataSet(); string MysqlStatement =

  • 0

Databinding

private DataSet BindGridView(List<int> userids)
   { DataSet ds = new DataSet();
     string MysqlStatement = "SELECT OrganisationID, OrganisationName FROM tbl_organisation WHERE OrganisationID=@OrganisationID";
    MySqlParameter[] param = new MySqlParameter[1];     
     foreach (var OrgID in userids)
    {
        param[0] = new MySqlParameter("@OrganisationID", MySqlDbType.Int32);
        param[0].Value = OrgID;
        ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param);
        ds.Merge(ds);
    }
    Grid_Organisationtable.DataSource = ds;
    Grid_Organisationtable.Columns[0].Visible = false;
    Grid_Organisationtable.DataBind();
    return ds;
}

I pass a list of values to the databinding method. I pass a list with organistionID. how should I do the databinding. It is returning an empty dataset. I am passing the list with values like 60,61,62. The error I am getting is

Unable to cast object of type ‘System.Collections.Generic.List`1[System.Int32]’ to type ‘System.IConvertible’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:56:51+00:00Added an answer on May 27, 2026 at 1:56 am

    You can’t pass in a list of id’s into an SQL query in this way. Your SELECT statement as it stands is expecting the parameter passed in to be a single value to be used by the WHERE clause.
    If you were to stick with this query you will need to loop through your list and pass in each value one at a time and make a seperate database call, for example:

    string MysqlStatement = "SELECT OrganisationID, OrganisationName FROM tbl_organisation WHERE OrganisationID=@OrganisationID";
    foreach(var id in userids)
    {
    
        MySqlParameter[] param = new MySqlParameter[1];     
        param[0] = new MySqlParameter("@OrganisationID", MySqlDbType.Int32);
        param[0].Value = id;      
        ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, param);
        ... add result to another list which is used to databind to your grid
    }
    

    A better alternative would be to use a WHERE...IN... clause and pass all your id’s in one go as this will only fire one database call and there is not need to pass in parameters:

    string MysqlStatement = string.Format("SELECT OrganisationID, OrganisationName FROM tbl_organisation WHERE OrganisationID IN ({0})", String.Join(",", userIds));
    ds = server.ExecuteQuery(CommandType.Text, MysqlStatement, null);
    

    Your third option would to write a stored procedure that accepted an xml string representation of your list and used this to query the database although this is somewhat more complicated. This way allows you to stick to using a parameter.

    Note: it is usually very bad practice to not pass in dynamic data as parameters as this can leave you open to Sql injection attacks but in this case as the data is coming from a List parameter passed into your method you can be fairly sure that it isn’t going to mess with your database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function for fetching data from a database via a dataset public
I'm fairly new to WPF and I have some problems getting databinding to work
I'm new to WPF and its Databinding, but I stumbled upon a strange behaviour
In my mvvm ViewModel I have such field public int Delta { get; private
When databinding my xaml to some data I often use the get part of
How do you perform databinding against the MonthCalendar.SelectionRange property? Given the property is of
I'm working with Databinding in ASP.Net 2.0, and I've come across an issue with
I am databinding a GridView to an object datasource. The gridview contains a TemplateField
any good recommendations for databinding. i am starting to look into WPF more and
When doing databinding does one have to implement INotifyPropertyChanged on the datacontext in WPF?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.