0

Need help,want to insert record via a webform ,but 2 of are my column data type are DateTime

this is part of my code:

string Name = txtName.Text;
         string Description = txtDecription.Text;
         string Topic = txtTopic.Text;
         string Sponsor = txtSponsor.Text;
         string Location = txtLocation.Text;
         DateTime StartDate;
            StartDate= DateTime.Parse(txtStartDate.Text);
         DateTime EndDate = DateTime.Parse(txtEndDate.Text);
         string URL = txtURL.Text;

         try
         {
            intResult = pBAL.Insert(Name,Description, Topic,Sponsor, Location,StartDate,EndDate, URL);
         }

Error:Cannot Convert from System.'DateTime' to 'string'

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by rohand
0

There are some possibilities for occuring this error.
1) It may be possible that your pBAL.Insert() accepts StartDate/EndDate as string type but you are passing StartDate/EndDate as DateTime.
2) another thing is you have defined StartDate/EdnDate as string type in database but you are trying to store datetime ..

check this and change it as per your requiremnt and let us know...

Need help,want to insert record via a webform ,but 2 of are my column data type are DateTime

this is part of my code:

     string Name = txtName.Text;
     string Description = txtDecription.Text;
     string Topic = txtTopic.Text;
     string Sponsor = txtSponsor.Text;
     string Location = txtLocation.Text;
     DateTime StartDate;
        StartDate= DateTime.Parse(txtStartDate.Text);
     DateTime EndDate = DateTime.Parse(txtEndDate.Text);
     string URL = txtURL.Text;

     try
     {
        intResult = pBAL.Insert(Name,Description, Topic,Sponsor, Location,StartDate,EndDate, URL);
     }

Error:Cannot Convert from System.'DateTime' to 'string'

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.