Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i dont know for some reason it is giving me error >> Incorrect syntax near 'PAKISTAN'.
C#
con.Open();
SqlCommand cmd = new SqlCommand("SELECT [phonecode] FROM [countryr] WHERE ([name] = PAKISTAN ");
cmd.Connection = con;
//cmd.Parameters.AddWithValue("@name", "PAKISTAN");
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
    TextBox1.Text = dr.GetValue(0).ToString();
    dr.Close();
}
con.Close();

i am unable to stand what i am doing wrong.
Posted
Updated 29-Jun-15 11:32am
v2

1 solution

you either need string marks (') in the query:
C#
"SELECT [phonecode] FROM [countryr] WHERE ([name] = 'PAKISTAN' )");


OR use the paramerter @name
C#
"SELECT [phonecode] FROM [countryr] WHERE ([name] = @name )");


parameters do not need string marks, strings do

hope that helps ^_^
Andy
 
Share this answer
 
v2
Comments
Member 11729398 29-Jun-15 17:46pm    
1st tried with adding (') string marks,
then tried with the parameter query but both of them didnt worked, still getting the same error. Its so weird.
Andy Lanng 29-Jun-15 17:50pm    
doh - we missed a bracket - updating solution
Member 11729398 29-Jun-15 18:00pm    
thank you sir :)
Andy Lanng 29-Jun-15 18:02pm    
p - don't forget to accept the solution ^_^

It's 11pm I'm off. good luck ;)
Member 11729398 29-Jun-15 18:09pm    
sure, i accepted it. Good night

regards, Salman

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