字符串未被识别为有效的TimeSpan。 [英] String was not recognized as a valid TimeSpan.

查看:135
本文介绍了字符串未被识别为有效的TimeSpan。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解决这个问题???????



I want slove this problum ???????



错误消息



字符串未被识别为有效的TimeSpan。

描述:在执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.FormatException:String未被识别为有效的TimeSpan 。



来源错误:





第178行:dropdowncourier.SelectedItem .Text = phoneGridView.SelectedRow.Cells [2] .Text;

第179行:dropdowngetphone.SelectedItem.Text = phoneGridView.SelectedRow.Cells [3] .Text;

第180行:TimeSpan PKTime = TimeSpan.Parse(phoneGridView.SelectedRow.Cells [4] .Text);

第181行:int hours = PKTime.Hours;

第182行:int Minutes = PKTime.Minutes;


ERROR Message

String was not recognized as a valid TimeSpan.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid TimeSpan.

Source Error:


Line 178: dropdowncourier.SelectedItem.Text= phoneGridView.SelectedRow.Cells[2].Text;
Line 179: dropdowngetphone.SelectedItem.Text = phoneGridView.SelectedRow.Cells[3].Text;
Line 180: TimeSpan PKTime = TimeSpan.Parse(phoneGridView.SelectedRow.Cells[4].Text);
Line 181: int hours = PKTime.Hours;
Line 182: int Minutes = PKTime.Minutes;







MY CODE






MY CODE

 dropdowncourier.SelectedItem.Text= phoneGridView.SelectedRow.Cells[2].Text;
           dropdowngetphone.SelectedItem.Text = phoneGridView.SelectedRow.Cells[3].Text;
           TimeSpan PKTime = TimeSpan.Parse(phoneGridView.SelectedRow.Cells[4].Text);
                    int hours = PKTime.Hours;
                    int Minutes = PKTime.Minutes;
                    TimeSelector1.SetTime(hours, Minutes, TimeSelector1.AmPm);
   
          
txtremarks .Text = phoneGridView.SelectedRow.Cells[6].Text;

推荐答案

它只是说phoneGridView.SelectedRow.Cells [4] .Text的内容不能被识别为字符串形式的valie TimeSpan。我们无法解决这个问题:这是你的数据问题!



查看单元格内容,并在Parse方法描述/示例中: http://msdn.microsoft.com/en-us/library/se73z7b9.aspx [<一个href =http://msdn.microsoft.com/en-us/library/se73z7b9.aspxtarget =_ blanktitle =新窗口> ^ ] - 我不知道你的数据是什么看起来像,所以我们无法纠正你的问题。
It is simply saying that the contents of phoneGridView.SelectedRow.Cells[4].Text are not recognisable as a valie TimeSpan in string form. We can't fix that: it's your data that is the problem!

Have a look at the cell content, and at the Parse method description / example : http://msdn.microsoft.com/en-us/library/se73z7b9.aspx[^] - I don't know what your data looks like, so we can't correct your problem.


请试试这个,



Please Try this,

var dt = new DateTime(2010, 06, 26); // time is zero by default
               string currTime = "19:04:06";//dateTimePicker1.Value.TimeOfDay.ToString();//19:04:06
               var tm = TimeSpan.Parse(currTime);
               var fullDt = dt + tm;


这篇关于字符串未被识别为有效的TimeSpan。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆