Hello people,

I have an application that updates a table. In this application i have a combobox where i load id of record
on form load. Let me paste my code to be more clear about my problem.

Private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

  string q = "Select AREA, [PAYING AUTHORITY],[PURCHASE ORDER No], [BILL No], [BILL DATED], [MATERIAL VALUE], [BILL VALUE], [AMOUNT PASSED] , [SUPPLY PARTICULAR], [PAYMENT DETAILS], [C-FORM No], T_ID  from transact1 where t_id = '" +comboBox1.SelectedItem+ "' ";

                SqlCommand cmmd = new SqlCommand(q, on6);

                SqlDataReader drr = cmmd.ExecuteReader();


               
                while (drr.Read())
                {
                    //MessageBox.Show("Record With this Transaction Exist. Please Press OK to Continue.....");

                    txtarea.Text = drr["AREA"].ToString();
                    textBox2.Text = drr["PAYING AUTHORITY"].ToString();
                    richdescp.Text = drr["PURCHASE ORDER No"].ToString();
                    txtbill.Text = drr["BILL No"].ToString();
                    dateTimePicker1.Text = drr["BILL DATED"].ToString();
                    txtamt.Text = drr["MATERIAL VALUE"].ToString();
                    txtamtpas.Text = drr["BILL VALUE"].ToString();
                    textBox1.Text = drr["AMOUNT PASSED"].ToString();
                    richrem.Text = drr["SUPPLY PARTICULAR"].ToString();
                    txtchq.Text = drr["PAYMENT DETAILS"].ToString();
                    textBox3.Text = drr["C-FORM No"].ToString();

                    



                }
                drr.Close();
                


                    on6.Close();
               
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            }
}

Everytime i try to load data in the form. It gives me error that "String was not recognized as valid date time".
I tried lot of things but it didn't help. Can anybody please help me with this problem?

Thanks and Regards
Ajinkya

You have an error on row No.20. It should be like this:

dateTimePicker1.Value = Convert.ToDatetime(drr["BILL DATED"]);
commented: Nice. +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.