不可调用的成员'tostring'不能像方法一样使用 [英] Non-invocable member 'tostring' cannot be used like a method

查看:269
本文介绍了不可调用的成员'tostring'不能像方法一样使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我收到这样的错误



不可调用的成员'tostring'不能像方法一样使用


这行




cmd.Parameters.Add(@ Jdate,SqlDbType.Date).Value = DateTime.Now.ToString (dd / MM / yyyy);



可以帮助我一个人



我尝试了什么:



我试过向专业人士提出这个问题,但他们的解决方案无法修复此错误

Hi I am getting an error like this

"non-invocable member 'tostring' cannot be used like a method"

in this line

cmd.Parameters.Add("@Jdate", SqlDbType.Date).Value=DateTime.Now.ToString("dd/MM/yyyy");

can some one help me

What I have tried:

I have tried asking this problem to professionals but their solutions cannot fix this error

推荐答案

你可以试试这个

You can try this
cmd.Parameters.Add("@Jdate", SqlDbType.Date).Value=String.Format("{0:dd/MM/yyyy}", DateTime.Now);

简单:根本不要调用 ToString



您已将参数声明为 SQLD bType.Date 。这意味着它需要一个日期值,而不是一个字符串。



要么:
Simple: don't call ToString at all.

You've declared your parameter as SqlDbType.Date. That means it expects a date value, not a string.

Either:
cmd.Parameters.AddWithValue("@Jdate", System.DateTime.Today);



或:


or:

cmd.Parameters.Add("@Jdate", SqlDbType.Date).Value = DateTime.Today;



将有效。




will work.

引用:

DateTime.Now是一个命名空间,但它像变量一样使用

"DateTime.Now is a namespace but it is used like a variable"



这表明你创建了一个名称空间为 DateTime.Now ,或者您在文件顶部使用System; 指令错过



如果您在该命名空间中创建了一个文件,我强烈建议您更改它。创建与内置类型同名的名称空间不是一个好主意。


That suggests you've either created a file with a namespace of DateTime.Now, or you're missing the using System; directive from the top of your file.

If you've created a file in that namespace, I'd strongly suggest you change it. Creating namespaces with the same name as a built-in type is not a good idea.


这篇关于不可调用的成员'tostring'不能像方法一样使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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