0

I have a grid with two columns Product and Purchase_Date. i get the data from db and show it in grid. if i try to add one more data to this grid on button click using the following code, i get the error "type of value has a mismatch with column ...."

            DataTable dt = dataGridView1.DataSource as DataTable;
            if (dt != null)
            {
                DataRow row = dt.NewRow();
                dt.Rows.Add(textBox1.Text, dateTimePicker1.value);
                dataGridView1.DataSource = dt;
            }

How do i rectify it. i tried the following also datetime.parse,convert.todatetime,dateTimePicker1.value.ToString("yyyy-MM-dd hh:mm:ss").No use.

Ameena
  • 187
  • 2
  • 5
  • 18
  • What does `dateTimePicker1.value` return? Obviously not a `MySqlDateTime`, so do the necessary conversion. Also note that `dataGridView1`, `textBox1`, `dateTimePicker1` are bad names, you should really give your objects meaningful names. And why are you doing `DataRow row = dt.NewRow();` since you don't do anything with `row`? – BCdotWEB Feb 27 '15 at 13:34
  • how to convert a datetime value to mysqldatetime value? Thanks for the advice. i wil implement that. – Ameena Feb 27 '15 at 14:17
  • I have no idea, I've never user MySQL. Perhaps this helps: http://stackoverflow.com/questions/3633262/convert-datetime-for-mysql-using-c-sharp – BCdotWEB Feb 27 '15 at 14:40
  • I tried it @BCdotWEB. No Luck :( – Ameena Feb 27 '15 at 14:58

0 Answers0