Click here to Skip to main content
12,946,164 members (59,614 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to compare textbox value with the sql database value in c#?

im a beginner n i have to make a project. i only know how to connect database with the c# project. i m not asking for the exact code, kindly tell me any tutorial, link or anything that can help me.

One thing more, i dont have sql :( i have downloaded many setups but they r not complete. if anyone know any site from where i can get, do tell me please.
Posted 13-Jun-11 5:57am
Uday P.Singh 13-Jun-11 12:01pm
are you using Visual studio 2008/2010 then Sql server comes with Visual Studio
Sweety Khan 13-Jun-11 12:05pm
Really? i have just now installed VS 2010 n i have seen sql 2008 configuration manager with it but no management studio. kindly tell me a little bit mOre
Uday P.Singh 13-Jun-11 12:15pm
You can download Microsoft SQL Server 2008 Management Studio Express from here:
Sweety Khan 14-Jun-11 5:55am
its setup gives an error that it is not a valid win32 application
Uday P.Singh 14-Jun-11 12:45pm
I think you have downloaded the 64 bit version and you computer is 32 bit, so have to download this :SQLManagementStudio_x86_ENU.exe it is for 32 bit computer, and will work as desired.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

I think this will guide you.....
codesharper 14-Jun-11 13:26pm
good call, my 5
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can follow these steps:
1. using System.Data.SqlClient;

protected void Button1_Click(object sender, EventArgs e)
string str = "Data Source=ABC-PC\\SQLEXPRESS;Initial Catalog=demodb;Integrated Security=True";
            SqlConnection conn = new SqlConnection(str);
string adminId = txtadminId.Text;
string password = txtpassword.Text;
        string query = "SELECT admin_id, password FROM users WHERE id=@adminId
and password=@password";
        SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@admin_id", adminId);
cmd.Parameters.AddWithValue("@password", password);
SqlDataReader dr = cmd.ExecuteReader();

hope this helps:)
for more info comment here!!
Sweety Khan 14-Jun-11 16:19pm
what is the purpose of these lines?
cmd.CommandType = CommandType.Text;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@admin_id", adminId);
Kim Togo 14-Jun-11 16:43pm
It is called parameterized SQL, start using it :-)
Sweety Khan 14-Jun-11 17:03pm
i code this with the help of ur code n its working :)
string admin_id = A_TB1.Text;
string admin_password = A_TB2.Text;
SqlCommand c_admin_id = new SqlCommand("Select Admin_ID, Admin_Password from Administrator where Admin_ID = @admin_id and Admin_Password = @admin_password ", main_form);
c_admin_id.CommandType = CommandType.Text;
c_admin_id.Parameters.AddWithValue("@admin_id", admin_id);
c_admin_id.Parameters.AddWithValue("@admin_password", admin_password);
SqlDataReader r_admin_id = c_admin_id.ExecuteReader();
if (r_admin_id.HasRows)
Administrator a = new Administrator();
MessageBox.Show("ID or Password is invalid!");
Sweety Khan 14-Jun-11 17:05pm
thanx a lOt! n be there i will pOst mOre questions :)
Uday P.Singh 15-Jun-11 1:21am
Yes! suggested by Kim these statement comes into play, when we use parametrized query, and it is always better to use it, to avoid sql-injection atttacks.
Uday P.Singh 15-Jun-11 1:25am
welcome :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can refer to the following links to get your job done:[^]

Using ADO.NET for beginners[^]

hope this helps :)
Sweety Khan 14-Jun-11 7:20am
i have to compare user entered id n password with the database. so i specify sqlcommand n sqldatareader,tell me what to do next
SqlCommand c_admin_id = new SqlCommand("Select Admin_ID from Administrator ", main_form);
SqlDataReader r_admin_id = c_admin_id.ExecuteReader();
Sweety Khan 14-Jun-11 7:22am
A_TB1.text = r_admin_id.?
A_TB1 is a textbox. can i compare its value like this? what should i use in palce of ?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Microsoft:[^] just follow the instructions. It's not a small download - couple hundred meg IIRC - but it is worth it.

To use it, try starting with w3schools[^] and/or look at teh articles here: Beginners guide to accessing SQL Server through C#[^]
Sweety Khan 14-Jun-11 6:51am
w3schools is best
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Rate this: bad
Please Sign up or sign in to vote.

Solution 6

I am kind of trying to do the same thing and getting stuck..Help please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100