•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,594 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,479 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1584 | Replies: 1
![]() |
| |
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hi Everybody
i have been trying to develop a website for my company in asp.net using c# . i have a problem i login page . i am not able to connect it to my database so that i can match user name and password . plz tell me what mistake i am making.
i have been trying to develop a website for my company in asp.net using c# . i have a problem i login page . i am not able to connect it to my database so that i can match user name and password . plz tell me what mistake i am making.
C# CODE
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected bool ValidateUser(string userName, string passWord)
{
SqlConnection Conn;
SqlCommand cmd;
string lookupPassword = null;
try
{
Conn = new SqlConnection("Data Source=xxx;User ID=xxx;Password=xxxx");
Conn.Open();
cmd = new SqlCommand("Select pwd from users where uname = '@userName'", Conn);
cmd.Parameters.Add("@userName");
cmd.Parameters["@userName"].Value = userName;
lookupPassword = (string)cmd.ExecuteScalar();
cmd.Dispose();
Conn.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception ");
}
if (null == lookupPassword)
{
return false;
}
return (0 == string.Compare(lookupPassword, passWord, false));
}
}
.aspx CODE
private void cmdLogin_ServerClick(object sender, System.EventArgs e)
{
if (ValidateUser(txtUserName.Value, txtUserPass.Value))
FormsAuthentication.RedirectFromLoginPage(txtUserName.Value,
chkPersistCookie.Checked);
else
Response.Redirect("logon.aspx", true);
}
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
.net .net framework 3.0 access ajax asp avatar backup breach code combo custom daniweb data data protection database design developer development dom dropdownlist feed government hacker ibm medicine microsoft module msdn net news normalization office reader reuse security server skin software sql survey theme vista weather web windows workflow xml xoap
- Connect to a database using VB (VB.NET)
- VB: Connect to Access database via ODBC datasource name (Visual Basic 4 / 5 / 6)
- Sometimes an error come out "Could not connect to database".Why?? (Oracle)
- How to connect database using jTable (Java)
- How to connect Database in C???? (C)
- submiting info into a database for retrieval! (PHP)
- Using PHP to connect to remote MSSQL database (PHP)
- connect to password protected access db (Visual Basic 4 / 5 / 6)
- mySQL database searching for registration (MySQL)
- php wont submit data into the database (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: storing images into database
- Next Thread: Is there Win32 method in asp.net for.........


Hybrid Mode