Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible

Hi experts,
I am developing a c#/mysql window appln
in the below code I'm getting
 Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible Error at
dAdapter2.Fill(ds, "cl2");
pls help me to find a soln
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
 
namespace DataBinding
{
    
 
    public partial class Form1 : Form
    {
        MySqlConnection conn;
        MySqlDataAdapter dAdapter1;
        MySqlDataAdapter dAdapter2;
        DataSet ds;
        BindingSource bSource;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
           
            string connString = @"server=localhost;database=abc;user id=root;password=kodanda;";
            string sql = @"select client_mst.client_id as id,Concat(client_no,'   ' ,client_name) as client from client_mst";
            conn = null;
 
 
            try
            {
                conn = new MySqlConnection(connString);
                conn.Open();
 
                 dAdapter1 = new MySqlDataAdapter(sql, conn);
                MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(dAdapter1);
                ds = new DataSet();
                dAdapter1.Fill(ds,"Cl");
                bSource = new BindingSource();
                bSource.DataSource = ds.Tables["Cl"];
                clNamecomboBox.DataSource = bSource;
                MessageBox.Show(conn.Database);
                
                
                clNamecomboBox.DisplayMember = "client";
                clNamecomboBox.ValueMember = "id";
                
 
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error"+ex);
            }
        }
 
       
 
        private void clNamecomboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            string sql1 = @"select notes_date,notes_message from client_notes where client_id=?cid";
            dAdapter2 = new MySqlDataAdapter(sql1, conn);
 
 
            dAdapter2.SelectCommand.Parameters.Add("cid", MySqlDbType.Int32);
            dAdapter2.SelectCommand.Parameters["cid"].Value = clNamecomboBox.SelectedValue;
 
            dAdapter2.Fill(ds, "cl2");
            BindingSource bSource2 = new BindingSource();
            bSource2.DataSource = ds.Tables["cl2"];
            dataGridView1.DataSource = bSource2;           
                  
          
        }
        
    }
}

Open in new window

APPIREDDYAsked:
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.

Anurag AgarwalPython DeveloperCommented:
In the function form_load move the lines of code
clNamecomboBox.DisplayMember = "client";
 clNamecomboBox.ValueMember = "id";
ahead of line
clNamecomboBox.DataSource = bSource;

i.e. set the display member & value member before setting the datasource of the combobox. like
 clNamecomboBox.DisplayMember = "client";
 clNamecomboBox.ValueMember = "id";
clNamecomboBox.DataSource = bSource;
 
Anurag


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
APPIREDDYAuthor Commented:
Thanks Anurag

when i select different value from the combobox ,in the datagridview the data is appended everytime,
i don't want to append the data,insted i want to show only the rows of current selction,should i need to clear the datagridview data?
0
Anurag AgarwalPython DeveloperCommented:
Try to clear the Table cl2 from the dataset ds
ds.Tables["cl2"].Clear();
As i guess the data is appended in this table every time you are changing the combobox selection.
 
Anurag


0
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.