Incorrect syntax near the keyword 'User' in asp.net

Posted by Mandlaa under ASP.NET on 6/7/2013 | Points: 10 | Views : 2858 | Status : [Member] | Replies : 3
This is my code
I am getting following Error

ERROR:Server Error in '/' Application.
Incorrect syntax near the keyword 'User'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'User'.

string strConnection = ConfigurationManager.ConnectionStrings["stgdbConnectionString"].ConnectionString;
string strSelect = "SELECT Username,Password FROM User WHERE Username = @Username";

SqlConnection connection = new SqlConnection(strConnection);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;

SqlParameter email = new SqlParameter("@Username", SqlDbType.VarChar, 30);
email.Value = TextBox1.Text.Trim().ToString();
command.Parameters.Add(email);

//Create Dataset to store results and DataAdapter to fill Dataset
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
connection.Open();
dAdapter.Fill(dsPwd);
connection.Close();
if (dsPwd.Tables[0].Rows.Count > 0)
{
System.Net.Mail.MailMessage loginInfo = new System.Net.Mail.MailMessage();
loginInfo.To.Add(TextBox1.Text.ToString());
loginInfo.From = new MailAddress("a@gmail.com");
//loginInfo.Subject = "Forgot Password Information";

loginInfo.Body =TextBox2.Text+ "UserName: " + dsPwd.Tables[0].Rows[0]["Username"] + "Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("a@gmail.com", "a");
smtp.Send(loginInfo);
//Label1.Text = "Password is sent to you email id,you can now <a href='Login.aspx'>Login</a>";
}
else
{
Label1.Text = "Email Address Not Registered";
}




Responses

Posted by: aswinialuri-19361 on: 6/9/2013 [Member] Starter | Points: 25

Up
0
Down
Hi
I cant understand your query will you send me source code and database also


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/9/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Mandlaa

Can you highlight which line are you getting the error.

Is it in the select Query or the Connection string in Web.Config

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 6/14/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
I got the problem. There is no error in you code. The error "System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'User'. " is generated during the run time. This is because, you are trying to access the user table which is not present in you database. Make sure there is a use table in you database.

Hoe this will help you.



Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response