Click here to Skip to main content
15,889,499 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error



Line 18: string checkuser="select count(*) from UserData where User Name='" +TextBoxUN.Text + "'";
Line 19: SqlCommand com = new SqlCommand(checkuser, con);
Line 20: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
Line 21: if (temp == 1)
Line 22: {
Posted
Comments
Kornfeld Eliyahu Peter 26-Feb-14 6:56am    
And the error is?
harshavardhan12345678 26-Feb-14 7:00am    
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
con.Open();
string checkuser="select count(*) from UserData where UserName='" +TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkuser, con);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString ());
if (temp == 1)
Kornfeld Eliyahu Peter 26-Feb-14 7:02am    
You show your code, and that's fine but where and what the error is?!
harshavardhan12345678 26-Feb-14 7:03am    
error is in line 20

Two things, OK, three things...
1) When you report a problem TELL US WHAT THE PROBLEM IS. That means, if you get an error message, tell us what the message is, and where it occurs - otherwise we are just guessing...
2) Never do that: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. Particularly in a Web application, and in your login code...I could destroy your database from the other side of the world, without giving you any information about me...
3) Why are you converting an integer value to a string, in order to convert it right back to an integer again?

There is a very good chance that fixing (2) above will fix your problem...
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 26-Feb-14 7:07am    
TELL US WHAT THE PROBLEM IS
"DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously." - OG
:-) Just kidding...
OriginalGriff 26-Feb-14 7:17am    
:laugh:
Trust me, it was deliberate...
Why do some people assume we can read their minds on this stuff?
Instead Line 20: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());

Use

int temp = com.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