Hi all!
i want to validate the user name and password using an sql table i created.
i have tried the following code: -
SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
-
-
DataSet dsFillData = new DataSet();
-
-
SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
-
-
cmdobj.CommandType = CommandType.Text;
-
-
-
SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
-
-
-
daAdapter.Fill(dsFillData);
-
-
SqlDataReader dr = null;
-
-
myConnection.Open();
-
dr = cmdobj.ExecuteReader();
-
if(dr.Read())
-
{
-
Response.Write("Valid User");
-
}
-
else
-
{
-
Response.Write("Invalid User");
-
}
-
-
}
-
}
-
but my code seems to validate even the incorrect entries and also the fonts get enlarged on postback. can any body pls tell me what is the problem with this code? i'll be greatfull..
16 4722
try to use Select count(*) from tbl_LoginIDsets where user_name='username' and password='password'
if this query returns 1 then proceed further and login else reprompt for the correct username and password.
You didn't check for the entered username and password.
try to use Select count(*) from tbl_LoginIDsets where user_name='username' and password='password'
if this query returns 1 then proceed further and login else reprompt for the correct username and password.
i have now tried the following code: - SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
-
-
myConnection.Open();
-
-
Response.Write(ConnectionState.Open);
-
-
DataSet dsFillData = new DataSet();
-
-
SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
-
-
cmdobj.CommandType = CommandType.Text;
-
-
-
SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
-
-
-
daAdapter.Fill(dsFillData);
-
-
SqlDataReader dr = null;
-
-
SqlCommand cmd = new SqlCommand("Select * from tbl_LoginIDsets where LoginID = " +UserName +"and Password = " +Password, myConnection);
-
-
-
dr = cmd.ExecuteReader();
-
if(dr.Read())
-
{
-
Response.Write("Valid User");
-
}
-
else
-
{
-
Response.Write("Invalid User");
-
}
-
-
}
-
}
the command which i have underlined is giving the following error:
[Incorrect syntax near 'Password'.]
can you pls guide me where am i going wrong now? i'll be greatful.
You are missing some spaces e.g before "and Password = " needs to be " and Password = " ...
You need quotes around varchar type values.
You are missing some spaces e.g before "and Password = " needs to be " and Password = " ...
You need quotes around varchar type values.
i have iserted the spaces u suggested. the error hsa now changed to:
[The multi-part identifier "System.Web.UI.WebControls.TextBox" could not be bound.]
the error is still on the same line.
i have iserted the spaces u suggested. the error hsa now changed to:
[The multi-part identifier "System.Web.UI.WebControls.TextBox" could not be bound.]
the error is still on the same line.
In your code, where are Password and UserName values coming from?
In your code, where are Password and UserName values coming from?
the user and password values are entered by the user who wants to log in.
these values are to be validated from existing values in a table with feilds LoginID and Password
Post the full code that you used ...
Post the full code that you used ...
this is my complete 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 void Page_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
protected void LoginButton_Click(object sender, EventArgs e)
-
{
-
SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
-
-
myConnection.Open();
-
-
Response.Write(ConnectionState.Open);
-
-
DataSet dsFillData = new DataSet();
-
-
SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
-
-
cmdobj.CommandType = CommandType.Text;
-
-
-
SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
-
-
-
daAdapter.Fill(dsFillData);
-
-
SqlDataReader dr = null;
-
-
SqlCommand cmd = new SqlCommand("Select * from tbl_LoginIDsets where LoginID = " +UserName +" and Password = " +Password, myConnection);
-
-
-
dr = cmd.ExecuteReader();
-
if(dr.Read())
-
{
-
Response.Write("Valid User");
-
}
-
else
-
{
-
Response.Write("Invalid User");
-
}
-
-
}
-
}
could there be a problem in my connection? i'm just guessing though, because if i try to display my connection status it does say "open".
... -
DataSet dsFillData = new DataSet();
-
SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
-
cmdobj.CommandType = CommandType.Text;
-
SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
-
daAdapter.Fill(dsFillData);
-
-
1.) What is the code above doing in there?
2.) What are the names of the controls where the user enters the username and password?
1.) What is the code above doing in there?
2.) What are the names of the controls where the user enters the username and password?
1.) this code is supposed to fetch data from the table and fill the data set with this data using a data adapter (at least that is what i aimed to do, let me know if i am wrong)
2.) the user enters username and password into textboxes whose ID's are UserName and Password respectively
2.) the user enters username and password into textboxes whose ID's are UserName and Password respectively
Then to get the text entered you need to use UserName.Text and Password.Text not just UserName or Password.
Then to get the text entered you need to use UserName.Text and Password.Text not just UserName or Password.
i tried it.
but the only values it is now validating are the column names. if i enter any other values, even those which are present in my table, the debbuging stops and it gives me the following error:
[Invalid column name 'master'.
Invalid column name 'master'.]
both username=master and password=master should be valid entries according to my table.
i tried it.
but the only values it is now validating are the column names. if i enter any other values, even those which are present in my table, the debbuging stops and it gives me the following error:
[Invalid column name 'master'.
Invalid column name 'master'.]
both username=master and password=master should be valid entries according to my table.
Character datatypes also need to have quotes around them.
e.g - " where name = '" +name.Text + "'";
Character datatypes also need to have quotes around them.
e.g - " where name = '" +name.Text + "'";
it worked! It worked!! IT WORKED!!! Thank You!!!!
it worked! It worked!! IT WORKED!!! Thank You!!!!
Actually you did most of the work. Good luck with rest of it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lynn |
last post by:
Hello,
I am installing some databases on the mysql databases of my mac osx
10.2.8 but when I do "mysqlimport -u X -p W (directory) *.txt.table" I
am getting this answer:
mysqlimport: Error:...
|
by: andreas.maurer1971 |
last post by:
Hi all,
since a few years I use the following statement to find duplicate
entries in a table:
SELECT t1.id, t2.id,...
FROM table AS t1 INNER JOIN table AS t2
ON t1.field = t2.field
WHERE...
|
by: AK |
last post by:
Hi
Our product uses MS-SQL Server 2000. One of our customer has 10
installations with each installation stroring data in its own database.
Now the customer wants to consolidate these databases...
|
by: imrosie |
last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped....
I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
|
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= |
last post by:
Hi misters,
How I generate <tbodytag using Table, TableRow, etc ... controls ?
I have this method:
private Table GenerarTablaOrdenacion(LinkButton lnkAscendente, LinkButton
lnkDescendente,...
|
by: jelumalai |
last post by:
I am using display:none with using Table. When show the onClick using javascript. Then it will show, again i will hide, content only hidden, but that table doesn't hide.
<script>
function...
|
by: saurabhswati722 |
last post by:
My Urgent question :
How to validate textfield using Javascript in PHP?
|
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...
|
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...
|
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)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
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
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |