Skip to content

How to use datetimePicker in C#

Aman Jen

Asked Sep 1, 2013, 3:07 AM EDT1 answer
Share
LinkedInX
Hi,
    How to use Datetime Picker to insert record into sql Db usin C# code..below is my code..but isn't working , it's a Standalone Application

 AppointmentClass ap = new AppointmentClass();
            string dateString = this.dtP.Text;
int rown=   ap.insert(Convert.ToInt16(cboRepair.SelectedValue), tbDesc.Text, chkLinc.Checked, Convert.ToInt16(cboCustomer.SelectedValue),DateTime.Parse(dateString.ToString()));


showing error like below


when converting a string to datetime parse the string to take the date before putting each variable into Datetime



plz help...

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Are you getting format exception?

    Try the below one.

    string dateString = this.dtP.Text;

    DateTime temp = DateTime.Parse(dateString);

    int rown=   ap.insert(Convert.ToInt16(cboRepair.SelectedValue), tbDesc.Text, chkLinc.Checked, Convert.ToInt16(cboCustomer.SelectedValue),temp);

    0