473,320 Members | 2,104 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,320 software developers and data experts.

validate entries using an sql table

Hi all!

i want to validate the user name and password using an sql table i created.
i have tried the following code:

Expand|Select|Wrap|Line Numbers
  1. SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
  2.  
  3.         DataSet dsFillData = new DataSet();
  4.  
  5.         SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
  6.  
  7.         cmdobj.CommandType = CommandType.Text;
  8.  
  9.  
  10.         SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
  11.  
  12.  
  13.         daAdapter.Fill(dsFillData);
  14.  
  15.         SqlDataReader dr = null;
  16.  
  17.         myConnection.Open();
  18.         dr = cmdobj.ExecuteReader();
  19.                 if(dr.Read())
  20.                 {
  21.                     Response.Write("Valid User");
  22.                 }
  23.                 else
  24.                 {
  25.                     Response.Write("Invalid User");
  26.                 }
  27.  
  28.     }
  29. }
  30.  
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..
Jul 23 '08 #1
16 4722
debasisdas
8,127 Expert 4TB
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.
Jul 23 '08 #2
r035198x
13,262 8TB
You didn't check for the entered username and password.
Jul 23 '08 #3
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:


Expand|Select|Wrap|Line Numbers
  1.         SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
  2.  
  3.         myConnection.Open();
  4.  
  5.         Response.Write(ConnectionState.Open);
  6.  
  7.         DataSet dsFillData = new DataSet();
  8.  
  9.         SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
  10.  
  11.         cmdobj.CommandType = CommandType.Text;
  12.  
  13.  
  14.         SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
  15.  
  16.  
  17.         daAdapter.Fill(dsFillData);
  18.  
  19.         SqlDataReader dr = null;
  20.  
  21.         SqlCommand cmd = new SqlCommand("Select * from tbl_LoginIDsets where LoginID = " +UserName +"and Password = " +Password, myConnection);
  22.  
  23.  
  24.         dr = cmd.ExecuteReader();
  25.                 if(dr.Read())
  26.                 {
  27.                     Response.Write("Valid User");
  28.                 }
  29.                 else
  30.                 {
  31.                     Response.Write("Invalid User");
  32.                 }
  33.  
  34.     }
  35. }

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.
Jul 24 '08 #4
r035198x
13,262 8TB
You are missing some spaces e.g before "and Password = " needs to be " and Password = " ...
You need quotes around varchar type values.
Jul 24 '08 #5
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.
Jul 24 '08 #6
r035198x
13,262 8TB
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?
Jul 24 '08 #7
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
Jul 24 '08 #8
r035198x
13,262 8TB
Post the full code that you used ...
Jul 24 '08 #9
Post the full code that you used ...
this is my complete code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Data.SqlClient;
  11.  
  12. public partial class _Default : System.Web.UI.Page 
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.  
  17.     }
  18.  
  19.     protected void LoginButton_Click(object sender, EventArgs e)
  20.     {
  21.         SqlConnection myConnection = new SqlConnection("data source=myPC;database=myDB;uid=abc;password=abc123");
  22.  
  23.         myConnection.Open();
  24.  
  25.         Response.Write(ConnectionState.Open);
  26.  
  27.         DataSet dsFillData = new DataSet();
  28.  
  29.         SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
  30.  
  31.         cmdobj.CommandType = CommandType.Text;
  32.  
  33.  
  34.         SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
  35.  
  36.  
  37.         daAdapter.Fill(dsFillData);
  38.  
  39.         SqlDataReader dr = null;
  40.  
  41.         SqlCommand cmd = new SqlCommand("Select * from tbl_LoginIDsets where LoginID = " +UserName +" and Password = " +Password, myConnection);
  42.  
  43.  
  44.         dr = cmd.ExecuteReader();
  45.                 if(dr.Read())
  46.                 {
  47.                     Response.Write("Valid User");
  48.                 }
  49.                 else
  50.                 {
  51.                     Response.Write("Invalid User");
  52.                 }
  53.  
  54.     }
  55. }
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".
Jul 25 '08 #10
r035198x
13,262 8TB
...

Expand|Select|Wrap|Line Numbers
  1.         DataSet dsFillData = new DataSet();
  2. SqlCommand cmdobj = new SqlCommand("Select * from tbl_LoginIDsets", myConnection);
  3. cmdobj.CommandType = CommandType.Text;
  4. SqlDataAdapter daAdapter = new SqlDataAdapter(cmdobj);
  5. daAdapter.Fill(dsFillData);
  6.  
  7.  
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?
Jul 25 '08 #11
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
Jul 25 '08 #12
r035198x
13,262 8TB
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.
Jul 25 '08 #13
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.
Jul 25 '08 #14
r035198x
13,262 8TB
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
Expand|Select|Wrap|Line Numbers
  1. " where name = '" +name.Text + "'";
Jul 25 '08 #15
Character datatypes also need to have quotes around them.
e.g
Expand|Select|Wrap|Line Numbers
  1. " where name = '" +name.Text + "'";

it worked! It worked!! IT WORKED!!! Thank You!!!!
Jul 25 '08 #16
r035198x
13,262 8TB
it worked! It worked!! IT WORKED!!! Thank You!!!!
Actually you did most of the work. Good luck with rest of it.
Jul 25 '08 #17

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

Similar topics

0
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:...
3
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...
3
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...
1
imrosie
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...
3
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,...
1
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...
1
by: saurabhswati722 | last post by:
My Urgent question : How to validate textfield using Javascript in PHP?
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...
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...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
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
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...
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.