Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.56/5 (2 votes)
See more:
My code as follows;
C#
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
C#
cmd.Parameters.AddWithValue("studid", (int)txt_Studid.Text.Trim);
Posted
Updated 1-May-13 0:42am
v4
Comments
[no name] 1-May-13 8:01am    
Trim is a method not a property

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

C#
string str = txt_Studid.Text.Trim();


3. To convert string to integer use:

C#
int a = Convert.ToInt32(str);


Good luck, dude!
 
Share this answer
 
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900