找不到类型字符串时出错 [英] Error on type string not found

查看:90
本文介绍了找不到类型字符串时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过计时器更新网格列。

需要倒计时



catch错误类型字符串未找到的Addsecond

这是代码 https://gist.github.com/niwatpumkin/daa79edab4ffa08d4619 [ ^ ]





帮我解决

解决方案

1.在你的第一个代码块中,你已经存储在 Session 转换后的 DataTime 值的字符串值。然后在你的第二个块中读取该字符串并尝试直接使用 DateTime 方法( AddSecond )到字符串,这会产生错误。



2.解决方案是在会话中存储 DateTime 值而不是字符串(在你的第一个代码块中)。

 StartTime = DateTime.Now.AddMinutes(lbltime.Text )
Session( time)= StartTime



然后在第二个块中使用它,通过使用拆箱,并减少使用的多个ToString如下:

 CurrentTime =(DateTime)会话(  time' < span class =code-comment>从会话缓存的值中取消装箱! 
CurrentTime = CurrentTime.AddSeconds(-1)
lbltime.Text = CurrentTime.ToString( <温泉n class =code-string> HH:mm:ss


for variables StartTime和currentTime为它们分配datetime不转换tostring

所以修改这行代码

 StartTime = DateTime.Now.AddMinutes(lbltime.Text).ToString(  HH:mm:ss
CurrentTime = StartTime.ToString
----
CurrentTime = Session( time)。AddSeconds(-1).ToString()







将是



< pre lang =vb> StartTime = DateTime.Now.AddMinutes(lbltime.Text)
CurrentTime = StartTime
----
CurrentTime = Session( time)。AddSeconds(-1)


Session(需要将时间转换为日期时间


i want to update grid column by timer .
need to count down time

catch error Addsecond on type string not found
THIS IS CODE https://gist.github.com/niwatpumkin/daa79edab4ffa08d4619[^]


help me pls

解决方案

1.In your first code block, you have stored in your Session the string value, of the converted DataTime value. Then in your second block you read that string and try to use a DateTime method (AddSecond) directly to the string, and this generate the error.

2.The solution is to store in the session the DateTime value and not the string (in your first code block).

StartTime = DateTime.Now.AddMinutes(lbltime.Text)
Session("time") = StartTime


Then in the second block to use it, by using unboxing, and reduce the to many ToString used like bellow:

CurrentTime = (DateTime)Session("time") 'unboxing from the value from the Session cache!
CurrentTime = CurrentTime.AddSeconds(-1)
lbltime.Text = CurrentTime.ToString("HH:mm:ss")


for variables StartTime and currentTime assign datetime to them don't convert tostring
so modify this lines of code

StartTime = DateTime.Now.AddMinutes(lbltime.Text).ToString("HH:mm:ss")
CurrentTime = StartTime.ToString
----
CurrentTime = Session("time").AddSeconds(-1).ToString()




to be

StartTime = DateTime.Now.AddMinutes(lbltime.Text)
CurrentTime = StartTime
----
CurrentTime = Session("time").AddSeconds(-1) 


Session("time") would need to be cast to a datetime


这篇关于找不到类型字符串时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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