473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Login problem

Hi my Friends,

I dont know what is the problem in my code, Could somebody help me please??

===

this is the page:
===

Expand|Select|Wrap|Line Numbers
  1.  <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
  2. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  3.     <div align="left" style="text-align: center">
  4.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
  5.         <table style="z-index: 102; left: 290px; position: absolute; top: 50px">
  6.             <tr>
  7.                 <td align="center" style="width: 438px; height: 14px" valign="middle">
  8.                     &nbsp;</td>
  9.             </tr>
  10.             <tr>
  11.                 <td align="left" style="width: 438px" valign="middle">
  12.                     <table align="center">
  13.                         <tr>
  14.                             <td style="font-weight: bold; width: 265px">
  15.                                 &nbsp;Please login to access the Website<br />
  16.                             </td>
  17.                         </tr>
  18.                     </table>
  19.                 </td>
  20.             </tr>
  21.             <tr>
  22.                 <td align="left" style="width: 438px" valign="middle">
  23.                     <table align="center">
  24.                         <tr>
  25.                             <td style="width: 77px; height: 26px">
  26.                                 <asp:Label ID="Label1" runat="server" Text="User Name:"></asp:Label></td>
  27.                             <td style="width: 191px; height: 26px">
  28.                                 <asp:TextBox ID="userName" runat="server"></asp:TextBox></td>
  29.                         </tr>
  30.                         <tr>
  31.                             <td style="width: 77px">
  32.                                 <asp:Label ID="Label2" runat="server" Text="Password: "></asp:Label></td>
  33.                             <td style="width: 191px">
  34.                                 <asp:TextBox ID="passWord" runat="server" TextMode="Password"></asp:TextBox></td>
  35.                         </tr>
  36.                         <tr>
  37.                             <td style="width: 77px">
  38.                                 </td>
  39.                             <td style="width: 191px">
  40.                                 </td>
  41.                         </tr>
  42.                         <tr>
  43.                             <td style="width: 77px">
  44.                             </td>
  45.                             <td style="width: 191px">
  46.                                 <asp:Button ID="submit" runat="server" OnClick="submit_Click" Text="Submit" /></td>
  47.                         </tr>
  48.                     </table>
  49.                 </td>
  50.             </tr>
  51.         </table>
  52.         <br />
  53.         <br />
  54.         &nbsp; &nbsp;<br />
  55.         <br />
  56.         <br />
  57.         <br />
  58.         &nbsp; &nbsp;<br />
  59.         &nbsp; &nbsp;&nbsp;<br />
  60.         <br />
  61.         <br />
  62.         <br />
  63.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  64.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  65.         &nbsp; &nbsp; &nbsp;<br />
  66.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  67.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  68.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  69.         <br />
  70.     </div>
  71. </asp:Content> 
=========================
========================


this is the C# code for this page
=========
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12.  
  13. public partial class _Default : System.Web.UI.Page
  14. {
  15.     public void checkUser(String username, String password)
  16.     {
  17.         using (SqlCommand cmd = new SqlCommand())
  18.         {
  19.             cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionToEL"].ConnectionString);
  20.             cmd.CommandText = @"select * from " ;
  21.             cmd.Connection.Open();
  22.             SqlDataReader reader = cmd.ExecuteReader();
  23.             while (reader.Read())
  24.             {
  25.                 string name = reader[0].ToString();
  26.                 string pass = reader[1].ToString();
  27.                 if ((name.Equals(username)) && (pass.Equals(password)))
  28.                 {
  29.                     Response.Redirect( "StudentHome.aspx");
  30.  
  31.                 }
  32.             }
  33.             reader.Close();
  34.             cmd.Connection.Close();
  35.         }
  36.  
  37.         Response.Redirect("Default.aspx");
  38.  
  39.  
  40.  
  41.     }
  42.     protected void submit_Click(object sender, EventArgs e)
  43.     {
  44.         String n = this.userName.Text;
  45.         String p = this.passWord.Text;
  46.  
  47.         checkUser(n, p);
  48.  
  49.     }
  50.  
  51. }
  52.  
  53.  
========================

the problem is in the

"Line 22: SqlDataReader reader = cmd.ExecuteReader();"

???
Every thing else is OK regarding the Database. I created a table in the database with Mouza as username & 123457 as password.

Could somebody help me here... please...
Oct 22 '08 #1
6 1029
MrMancunian
569 Expert 512MB
Is there an error-message?

Steven
Oct 22 '08 #2
Is there an error-message?

Steven

when I run the application , it says to me:


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 'from'.

Source Error:


Line 20: cmd.CommandText = @"select * from ";
Line 21: cmd.Connection.Open();
Line 22: SqlDataReader reader = cmd.ExecuteReader();
Line 23: while (reader.Read())
Line 24: {



Source File: d:\Documents and Settings\myPC\My Documents\Visual Studio 2005\WebSites\E-CV\Default.aspx.cs Line: 22


--------------
when I debug it..
it says in the locals
$exception {"Incorrect syntax near 'from'."} System.Exception {System.Data.SqlClient.SqlException}
Oct 22 '08 #3
Thanks I solved the problem, I feel so stupid.
I did not specify the table the IAm getting the info from..

I have another question?
If iam logged in already, and I press back button. It should not ask me to write the username and the password again??

how can I do that?
could u help me?
Oct 22 '08 #4
MrMancunian
569 Expert 512MB
Try using a session and check wheter or not the session is active.

Steven
Oct 22 '08 #5
Curtis Rutland
3,256 Expert 2GB
But you will have to get around the browser cache. When you hit the back button, you aren't downloading the page again, it is showing you what it has stored in memory. I have read that this code will prevent that, but I haven't actually tried it myself.
Expand|Select|Wrap|Line Numbers
  1. Protected void Page_Init(object Sender, EventArgs e)
  2. {
  3. Response.Cache.SetCacheability(HttpCacheability.NoCache);
  4. Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
  5. }
  6.  
And then you will have to check in the Page_Load method if you are already logged in. I suggest that you set a Session variable true or false, and check that value.
Oct 22 '08 #6
But you will have to get around the browser cache. When you hit the back button, you aren't downloading the page again, it is showing you what it has stored in memory. I have read that this code will prevent that, but I haven't actually tried it myself.
Expand|Select|Wrap|Line Numbers
  1. Protected void Page_Init(object Sender, EventArgs e)
  2. {
  3. Response.Cache.SetCacheability(HttpCacheability.NoCache);
  4. Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
  5. }
  6.  
And then you will have to check in the Page_Load method if you are already logged in. I suggest that you set a Session variable true or false, and check that value.

I tried it, but it doesn't work
I searching also!!
Iam confused
Oct 23 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Sniffer-Dog | last post by:
Hi I just wondered if anyone can spot anything wrong with the following? I have now added the session_start(); as the first command in the code to all the pages needing it. When I click on a...
5
by: Simon | last post by:
Hi, I have a Login.php page that logs the user in and out. I has two forms within the page, (depending on what we are trying to do), either one to log in or out. The form calls itself using a...
1
by: John Davis | last post by:
I put a little login (username and password textfields) in a web page, and once the user able to login, I want the username and password textfields will disappear, and replace with text " has...
0
by: Mike | last post by:
I can not figure out what is going on here. I hope somebody can please help!!! I've got an intranet ASP3 application running on a Win2k server. This application requires a login, so the user...
1
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to...
2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
2
by: Rujuta Gandhi | last post by:
Hi All, I am facing a very crucial problem. Im developing a web application using .net studio 2005(beta). I want my Login.aspx page to be secured(https) for encrypted login information...
1
by: xcelmind | last post by:
Hello Dev. Guru, I want to at this time introduce myself. I am Stanley Ojadovwa by name. I’m a freelance and a newbie in web application development. I’m currently using ASP as my application...
4
by: RN1 | last post by:
I am working on WinXP Pro SP3, .NET 2.0 & SQL Server 2005 (Windows Authentication). When I run a ASPX page that connects to SQL Server, the following error gets generated: Login failed for user...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.