Click here to Skip to main content
15,915,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Line 18: string CheckUser="select count(*) from UserData where UserName='" +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:





error in line 20
Posted
Updated 27-Jan-18 19:29pm
Comments
Tom Marvolo Riddle 26-Feb-14 23:28pm    
what's the error?
harshavardhan12345678 26-Feb-14 23:30pm    
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
harshavardhan12345678 26-Feb-14 23:30pm    
error in line 20
Priya Dharshini Aug2022 4-Aug-22 4:36am    
Incorrect syntax near','
Karthik_Mahalingam 26-Feb-14 23:31pm    
what error message you are getting ?

Columns in the SQL queries should be enclosed in Square Bracket if the Column Name contains special character or Space . So use [User Name] in your Select and insert queries.
 
Share this answer
 
Comments
Karthik_Mahalingam 27-Feb-14 1:43am    
5, for providing information.
JoCodes 27-Feb-14 2:00am    
Thanks alot Karthik.
Try the below code..
protected void Page_Load(object sender, EventArgs e)
       {
           if (IsPostBack)
           {
               try
               {
                   SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
                   con.Open();
                   string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUN.Text + "'";
                   SqlCommand com = new SqlCommand(checkuser, con);
                   int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
                   if (temp == 1)
                   {
                       Response.Write("User already Exists");
                   }

               }

               catch (Exception ex)
               {
                   Response.Write(ex.Message);
               }
               finally
               {
                   con.Close();
               }
           }
       }
 
Share this answer
 
Try this

C#
string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUN.Text + "'";
 
Share this answer
 
Comments
JoCodes 27-Feb-14 2:01am    
5 , for the code :)
Karthik_Mahalingam 27-Feb-14 2:04am    
:)
Siva Hyderabad 28-Feb-14 6:58am    
+5

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