无法将方法组'Trim'转换为非委托类型'int' [英] Cannot convert method group 'Trim' to non-delegate type 'int'

查看:674
本文介绍了无法将方法组'Trim'转换为非委托类型'int'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下;

  string  str =  从Student中选择count(*),其中studid = @ studid;; 
SqlCommand cmd = new SqlCommand(str,SCon.Con);
cmd.Parameters.AddWithValue( studid,( INT )txt_Studid.Text.Trim);
int count =( int )cmd.ExecuteScalar();



当我运行上面的代码时显示错误如下;

无法将方法组'修剪'转换为非委托类型'int 。你打算调用这个方法吗?



上面的代码有什么问题。



错误显示在以下行中

 cmd.Parameters.AddWithValue(  studid,( int )txt_Studid.Text.Trim); 

解决方案
1。修剪是一种方法:使用txt_Studid.Text.Trim()作为 txt_Studid.Text.Trim

2.修剪'的返回值是字符串为int:use



  string  str = txt_Studid.Text.Trim(); 





3.要将字符串转换为整数使用:



  int  a = Convert.ToInt32(str); 





祝你好运,伙计!


你好,

请试试这个代码..



string str =从Student中选择count(*),其中studid = @ studid;;

SqlCommand cmd = new SqlCommand(str,SCon.Con);

cmd。 Parameters.AddWithValue(studid,(int)txt_Studid.Text.Trim());

int count =(int)cmd1.ExecuteScalar();


My code as follows;

string str = "Select count(*) from Student where studid=@studid;";
SqlCommand cmd = new SqlCommand(str, SCon.Con);
cmd.Parameters.AddWithValue("studid", (int)txt_Studid.Text.Trim);
int count = (int)cmd.ExecuteScalar();


when i run the above code shows error as follows;

Cannot convert method group 'Trim' to non-delegate type 'int'. Did you intend to invoke the method?


what is the problem in my above code.

Error shows in following line

cmd.Parameters.AddWithValue("studid", (int)txt_Studid.Text.Trim);

解决方案

1. Trim is a method: use rather txt_Studid.Text.Trim() as txt_Studid.Text.Trim
2. Trim''s return value is rather string as int: use

string str = txt_Studid.Text.Trim();



3. To convert string to integer use:

int a = Convert.ToInt32(str);



Good luck, dude!


Hello,
Please try this code..

string str = "Select count(*) from Student where studid=@studid;";
SqlCommand cmd = new SqlCommand(str, SCon.Con);
cmd.Parameters.AddWithValue("studid", (int)txt_Studid.Text.Trim());
int count = (int)cmd1.ExecuteScalar();


这篇关于无法将方法组'Trim'转换为非委托类型'int'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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