Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
4.60/5 (3 votes)
See more:
unable to cast object of type 'system.data.datarowview' to type 'system.iconvertible'
i have this type of error plz help me anyone
C#
private void BindClassGroupCmb()
{
    //Show existing record list.
    try
    {

        ClassGroup = _ExcuteData._ExecuteDataSet("SELECT class_group_name, class_groupid from class_group_master ");
       //cmbClassGroup.Items.Insert(0, "--Select--");
        cmbClassGroup.DataSource = ClassGroup.Tables[0];

        cmbClassGroup.DisplayMember = "class_group_name";
        cmbClassGroup.ValueMember = "class_groupid";
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
Posted

1 solution

Try like this


C#
cmbClassGroup.DisplayMember = "class_group_name";
        cmbClassGroup.ValueMember = "class_groupid";
        cmbClassGroup.DataSource = ClassGroup.Tables[0];


you have to define the Valuemember and Displaymember before assigning a datasource...
 
Share this answer
 
Comments
Tripat Bala Singh 22-Jan-14 8:27am    
thank you kartihik sir its working...
thank you very much...
Karthik_Mahalingam 22-Jan-14 8:33am    
welcome :)
Abhinandan Taralkar 6-Nov-14 1:28am    
thanks it's what i want
Karthik_Mahalingam 10-Nov-14 3:15am    
welcome :)
Member 11057488 24-Apr-15 3:48am    
unable to cast object of type system.data.datarowview to typ system.iconvertible in c#.net index out of bound

public void Bind()
{
try
{
string query = @"select ProductMaster.id,ProductMaster.pName,ProductDetails.Modelno,ProductDetails.Price,ProductDetails.Quantity from ProductMaster, ProductDetails";
sda = new SqlDataAdapter(query, conn);
dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
dataGridView1.Columns[0].Visible = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900