i have two textboxes one for user name and another for
password . i have a table name compare(which contains
name,passwod etc.,)my doubt is how compare username
textbox with name column and how compare password textbox
with passwod column. i want the code

Answer Posted / deepak,the infotech icon

sqlConnection con=new sqlConnection();
con.Connectionstring="Data source=servername;Initial
Catalog=databasename;Integrated Security=sspi";
con.open();
string query="SELECT * FROM tablename where name=@name AND
password=@password";
sqlCommand cmd=new sqlCommand(query,con);
cmd.parameters.add(new sqlparameters(@name,textbox1.text));
cmd.parameters.add(new sqlparameters(@password,textbox2.text));
sqlDataReader dr=cmd.Executereader();
while(dr.read())
{
if((textbox1.text==dr[0])&&(textbox2.text==dr[1]))
{
Messagebox.show("YOU ARE SUCCESSFULLY LOGED IN");
return;
}
}
Messagebox.show("INVALID USERNAME OR PASSWORD");

Is This Answer Correct ?    2 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we do database operations without using any of the ado.net objects?

541


Explain the difference in an abstract class and an interface?

509


What are the key features of ado.net?

676


What are the features of ado.net?

511


What is ado.net code?

530






What are the usages of the command object in ado.net?

564


What is ado.net and its architecture?

511


What is command class in ado.net?

487


What is the difference between sqldatareader and sqldataadapter?

502


What is difference between executenonquery and executequery?

478


What is the functionality of data provider in ado.net?

497


How can we add/remove row's in "datatable" object of "dataset"?

552


Command objects uses, purposes and their methods.

533


What are the key events of sqlconnection class?

622


What is the purpose of using adodb?

517