using session var in sql ASP C#

Joined
Nov 18, 2010
Messages
1
Reaction score
0
Hi

Please help me with the following.
This is my code:

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 am getting:

Code:
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())


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

Stack Trace:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top