如何检查用户输入的内容并将其与数据库值进行比较

时间:2014-03-07 12:02:02

标签: c# asp.net visual-studio-2012

    string abc = WebConfigurationManager.ConnectionStrings["connectionName"].ConnectionString;

    SqlConnection con = new SqlConnection(abc);
    SqlCommand cmd = new SqlCommand("SELECT UserName ,Password from [Login] WHERE UserName =@usern AND Password = @pass", con);
    con.Open();

    cmd.Parameters.AddWithValue("@usern", username1.Text);
    cmd.Parameters.AddWithValue("@pass", TextBox9.Text);
    try
    {
        //if user iputs = to the values in my DB

        Response.Redirect("Userinfo.aspx?id=" + username1.Text);
    }
     //if user iputs != to the values in my DB
    catch(SqlException ex)

    {
       //error
        Label1.Visible = true;
    }
    cmd.ExecuteNonQuery();
    con.Close();

即使用户输入!=我的数据库中的值

,也会使用try语句

0 个答案:

没有答案