0

Hi

Please help with the following.

This is my code:

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Import Namespace="System.Data.SqlClient"%> 
<%@ Import Namespace="System.Data.OleDb"%> 

<html>
<head>
<title>Session Page 2</title>
</head>
<body><p>ASP.NET C# session page 2</p>
<p>first name: <%=Session["FirstName"]%></p>
<p>Password: <%=Session["Password"]%></p>
<% 
  Response.Write(Session["FirstName"]);
  Response.Write("Connecting to db");
  OleDbConnection Myconnection= null;
  OleDbDataReader dbReader = null;
  Myconnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\besa.accdb");
  Myconnection.Open();
  string Firstname = Session["FirstName"].ToString();
  OleDbCommand cmd = Myconnection.CreateCommand();
  cmd.CommandText ="select password from user where username=='" + Session["FirstName"] + "'";
  dbReader = cmd.ExecuteReader();
  /* 
   while (dbReader.Read())
   {Response.Write(dbReader.GetString(1));}
    dbReader.Close(); 
  */
  Myconnection.Close();
  Response.Write("end of prog");
%>			
    
</body>
</html>

The error I get is as follow:

Syntax error in FROM clause.
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.OleDb.OleDbException: Syntax error in FROM clause.

Source Error:

Line 24:   OleDbCommand cmd = Myconnection.CreateCommand();
Line 25:   cmd.CommandText ="select password from user where username=='" + Session["FirstName"] + "'";
Line 26:   dbReader = cmd.ExecuteReader();
Line 27:   /* 
Line 28:    while (dbReader.Read())

Thank you!

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by catherine sea
0

While I doubt it is the reason for your error, is there a reason you are using Session["FirstName"] in the CommandText? You have already created the variable Firstname from Session["FirstName"] and cast it as a string.

0

While I doubt it is the reason for your error, is there a reason you are using Session["FirstName"] in the CommandText? You have already created the variable Firstname from Session["FirstName"] and cast it as a string.

Hi

Thank you for the reply :

The following code still give's the error

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Xml.Linq" %>
<%@ Import Namespace="System.Data.SqlClient"%> 
<%@ Import Namespace="System.Data.OleDb"%> 

<html>
<head>
<title>Session Page 2</title>
</head>
<body><p>ASP.NET C# session page 2</p>
<p>first name: <%=Session["FirstName"]%></p>
<p>Password: <%=Session["Password"]%></p>
<% 
  Response.Write(Session["FirstName"]);
  Response.Write("Connecting to db");
  OleDbConnection Myconnection= null;
  OleDbDataReader dbReader = null;
  Myconnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\besa.accdb");
  Myconnection.Open();
  string Firstname = Session["FirstName"].ToString();
  OleDbCommand cmd = Myconnection.CreateCommand();
  cmd.CommandText = "select password from user where username='"+Firstname+"'";
  dbReader = cmd.ExecuteReader();
  /* '" + Session["FirstName"] + "'";
   while (dbReader.Read())
   {Response.Write(dbReader.GetString(1));}
    dbReader.Close(); 
  */
  Myconnection.Close();
  Response.Write("end of prog");
%>			
    
</body>
</html>

error:

Server Error in '/WebSite1' Application.
Syntax error in FROM clause.
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.OleDb.OleDbException: Syntax error in FROM clause.

Source Error:

Line 24:   OleDbCommand cmd = Myconnection.CreateCommand();
Line 25:   cmd.CommandText = "select password from user where username='"+Firstname+"'";
Line 26:   dbReader = cmd.ExecuteReader();
Line 27:   /* '" + Session["FirstName"] + "'";
Line 28:    while (dbReader.Read())


Source File: c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\testpassword.aspx    Line: 26

Stack Trace:

[OleDbException (0x80040e14): Syntax error in FROM clause.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1003520
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +255
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +188
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +161
   System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +116
   System.Data.OleDb.OleDbCommand.ExecuteReader() +6
   ASP.testpassword_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\WebSite1\testpassword.aspx:26
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.