Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server
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 Frown | :( 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 6:57am
Comments
Uday P.Singh at 13-Jun-11 12:01pm
   
are you using Visual studio 2008/2010 then Sql server comes with Visual Studio
Sweety Khan at 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 at 13-Jun-11 12:15pm
   
You can download Microsoft SQL Server 2008 Management Studio Express from here: http://www.microsoft.com/download/en/details.aspx?id=7593
Sweety Khan at 14-Jun-11 5:55am
   
its setup gives an error that it is not a valid win32 application
Uday P.Singh at 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
good
Please Sign up or sign in to vote.

Solution 4

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

Solution 3

You can follow these steps:
1. using System.Data.SqlClient;
 
2.
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);
        conn.Open();
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 helpsSmile | :)
for more info comment here!!
  Permalink  
Comments
Sweety Khan at 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 at 14-Jun-11 16:43pm
   
It is called parameterized SQL, start using it :-)
Uday P.Singh at 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.
Sweety Khan at 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();
a.Show();
}
else
MessageBox.Show("ID or Password is invalid!");
Sweety Khan at 14-Jun-11 17:05pm
   
thanx a lOt! n be there i will pOst mOre questions :)
Uday P.Singh at 15-Jun-11 1:25am
   
welcome :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can refer to the following links to get your job done:
 
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx[^]
 
Using ADO.NET for beginners[^]
 
hope this helps Smile | :)
  Permalink  
Comments
Sweety Khan at 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 at 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
good
Please Sign up or sign in to vote.

Solution 1

Microsoft: http://www.microsoft.com/express/Database/[^] 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#[^]
  Permalink  
Comments
Sweety Khan at 14-Jun-11 6:51am
   
w3schools is best
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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

Solution 6

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

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
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