By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

Login problem

P: 17
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
Share this Question
Share on Google+
6 Replies


MrMancunian
Expert 100+
P: 569
Is there an error-message?

Steven
Oct 22 '08 #2

P: 17
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

P: 17
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
Expert 100+
P: 569
Try using a session and check wheter or not the session is active.

Steven
Oct 22 '08 #5

Curtis Rutland
Expert 2.5K+
P: 3,256
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

P: 17
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

Post your reply

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