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
Answers were Sorted based on User's Feedback
Answer / anjaneyulu
U will compare the 2 textboxes values i.e.username &
password with the database values by writing the following code:
cn.Open();
SqlCommand cmd = new SqlCommand("select count(*)
from compare where username='" + TextBox1.Text + "'and
password='" + TextBox2.Text + "'", cn);
int count = (int)cmd.ExecuteScalar();
cn.Close();
if (count != 0)
{
Page.RegisterStartupScript("pr",
"<script>alert('welcome to MS.Net')</script>");
}
else
{
Page.RegisterStartupScript("an",
"<script>alert('sorry')</script>");
}
Is This Answer Correct ? | 16 Yes | 3 No |
Answer / rahul dabur
//Make a store procedue with name dbologin
Create PROCEDURE dbologin
(
@uid varchar(50),
@Pass varchar(50)
)
AS
declare @pwd varchar(50)
select @pwd=Password from tbllogin where UName=@uid and
Password=@Pass
if @pwd is null
return 1
else if @pwd=@Pass
return 2
//At a button click event with connected approach
protected void btnlogin_Click(object sender, EventArgs e)
{
// string textStr ;
SqlCommand cmd = new SqlCommand("dbologin", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@uid", SqlDbType.VarChar,
50).Value = Convert.ToString(txtusername.Text);
cmd.Parameters.Add("@Pass", SqlDbType.VarChar,
50).Value = Convert.ToString(txtpassword.Text);
// textStr = Convert.ToString(txtpassword.Text);
//textStr = cmd.Parameters.Add("@Pass",
SqlDbType.VarChar, 50).Value.ToString();
// textStr = cmd.Parameters.Add("@Pass",
SqlDbType.VarChar, 50).Value;
SqlParameter p1 = new SqlParameter("@s", SqlDbType.Int);
p1.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p1);
cmd.ExecuteNonQuery();
Int32 k = Convert.ToInt32(cmd.Parameters["@s"].Value);
if (k == 1)
{
Label1.Text = "Wrong UserName and password";
}
else
{
Label1.Text = "Right UserName and Password";
Response.Redirect("calculator.aspx");
}
cmd.Dispose();
con.Close();
txtusername.Text = string.Empty;
txtpassword.Text = string.Empty;
// Response.Redirect("calculator.aspx");
}
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / sonj
dim qry as string = SELECT name,password FROM compare where
name = '" + txtName.text + "' AND password = '" +
txtPassword.txt + "'"
Dim ConectionString As String = "User ID=xxx;Password = yyy;
Initial Catalog='" + DataBaseName + "';Data Source=<System No>"
dim con as SqlConnection = New SqlConnection(ConectionString )
con.open
dim cmd as SqlCommand = new SqlCommand(qry,con)
dim dr as SqlDataReader = cmd.ExectueReader
if dr.HasRows = True then
messagebox.show("User ID Found")
else
messagebox.show("User ID Not Found")
end if
Above is the one example. There are various ways to validate
fox example you can write a stored procedure to validate
ID,Password and avoid SQL Injection etc.,
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / suchit kumar dash
Dim con as new SqlConnection
Dim cmd as new SqlCommand
Dim dr as SqlDataReader
Dim str,str1 as String
Dim I_Int as Integer=0
PageLoad
--------------
str="Server=......;Database=......;Trusted_Connection=Yes;User
Id=sa;Password=sa;"
con=new SqlConnection(str)
Login BUtton
--------------
str1="select * from TableName where User_Name='"&
TextBox1.Text &"' and Password='" & TextBox2.Text &"'"
cmd=New SqlCommand(str1,con)
dr=cmd.ExecuteReader
while(dr.Read())
i_int=i_int+1
End while
if i=0 then
MessageBox.Show("Please Enter correct User Id and Password")
else
Endif
Is This Answer Correct ? | 3 Yes | 3 No |
Answer / sushil kumar
Follow blog AspMaterials.blogspot.com . Here login example from this you can understand.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / boopathiraj
sqlconnection con = new sqlconnection("");
sqlcommand cmd = new sqlcommand("select * from
table-name",con);
//write this code in the button click event
con.open();
dr = cmd.executereader();
while(dr.read())
{
if(textbox1.text==dr.getvalue(0).tostring()&&
textbox2.text==dr.getvalue(1).tostring())
{
msgbox.show("successful");
}
}
con.close();
else
{
msgbox.show("not success");
}
Is This Answer Correct ? | 3 Yes | 4 No |
Answer / srilekha
{
string s=string.Format("select * from compare where
name='{0}' and Password='{1}'",textbox1.Text,textbox2.Text);
SqlDataAdapter da=new SqlDataAdapter (s,conn);
DataTable dt=new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Lable1.text="login successfull";
}
else
{
Lable1.text="login fail";
}
Is This Answer Correct ? | 1 Yes | 3 No |
Answer / 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 |
Answer / vijay
sqldatasource s=new sqldatasource();
s.connectionstring=configurationmanager.connectionstring
["compareconnectionstring"].connectionstring;
s.selectcommand="select count(*) from compare where uid='"
+ textbox1.text + "'and pwd='" + textbox2.text + "'";
Dataview dv=new dataview();
dv=(dataview)s.select(datasourceselectarguments.empty)
if(dv[0][0]>0){} //found
else{}//not found
Is This Answer Correct ? | 0 Yes | 5 No |
What is ado object model?
Difference between OLEDB Provider and SqlClient ?
What is difference between sqldatareader and sqldataadapter?
Explain the advantages and disadvantages of using datalist?
Do we use stored procedure in ADO.Net?
What is ODP.NET ?
Difference between datareader and dataset?
26 Answers Microsoft, Noel Infotech, Satyam, Value Labs,
can u tell me the why ADO does not support xml..
If a dataset contains 100 rows, how to fetch rows between 10 and 20 only ?
What is @@rowcount and with small code snippet explain the usage?
what is the syntax code for oldb to connect oracle
What is ole in excel?