收到错误:String引用没有设置为String的实例。参数名称:S [英] Getting error: String reference not set to an instance of a String. Parameter name: s

查看:7762
本文介绍了收到错误:String引用没有设置为String的实例。参数名称:S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这code截断从我的数据库日期时间到了一年时间的成分。变量YearOfRelease和Runtime包含格式的日期时间DD / MM / YYYY HH:MM:SS这是pviously工作的罚款$ P $但现在给人的错误:

String引用没有设置为String的实例。
参数名称:S

它只能是一些错误的DateTime.ParseExact功能,任何人都可以请让我知道为什么'空'突然引起此问题时previously它可以正常使用?

 日期时间DT2 =新的DateTime();
    DT = DateTime.ParseExact(YearOfRelease,DD / MM / YYYY HH:MM:SS,NULL);    年= dt.Year.ToString();
    DT2 = DateTime.ParseExact(运行时,DD / MM / YYYY HH:MM:SS,NULL);
    字符串小时= dt2.Hour.ToString();
    串分钟= dt2.Minute.ToString();    时间=小时+:+分钟;


解决方案

DateTime.ParseExact 是一个名为S字符串参数。

因此​​,它看起来像YearOfRelease或运行时间是在你的程序无效。确保那些你打电话之前DateTime.ParseExact设置。

I am using this code to truncate datetime from my database into its year and time components. The variables YearOfRelease and Runtime contain datetime of the format "dd/MM/yyyy hh:mm:ss" It was working fine previously but its now giving the error:

String reference not set to an instance of a String. Parameter name: s

It could only be something wrong in the DateTime.ParseExact function, could anyone please let me know why 'null' is suddenly causing this problem when previously it was working perfectly?

    DateTime dt2 = new DateTime();


    dt = DateTime.ParseExact(YearOfRelease, "dd/MM/yyyy hh:mm:ss", null);

    Year = dt.Year.ToString();


    dt2 = DateTime.ParseExact(RunTime, "dd/MM/yyyy hh:mm:ss", null);
    string hour = dt2.Hour.ToString();
    string min = dt2.Minute.ToString();

    Time = hour + ":" + min;

解决方案

The first parameter of DateTime.ParseExact is a string parameter named 's'.

Therefore, it looks like YearOfRelease or RunTime is null in your program. Make sure those are set before you call DateTime.ParseExact.

这篇关于收到错误:String引用没有设置为String的实例。参数名称:S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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