SQL_搜索语句

来源:互联网 发布:arcgis for js 点闪烁 编辑:程序博客网 时间:2024/05/28 15:57

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

 

//登录搜寻匹配例子

string cmdtext1 = "select * from Staff where s_logname='" + this.tname.Text +"' and s_password='" +this.tpass.Text + "'";  //Staff库,s_logname&s_password数据Design Name;

                SqlConnection con =newSqlConnection("Server=localhost;database=qcwx;uid=sa;pwd=sasasa"); //创建连接

                con.Open();

                SqlCommand cmd =newSqlCommand(cmdtext1, con);

                try

                {

                    SqlDataReader dr = cmd.ExecuteReader();

                    if (dr.Read())

                    {

 

                        MessageBox.Show("登录成功!");

                        sqlconn.Close();

                        Response.Redirect("user/Usermb.aspx");

 

                    }

                    else

                    {

                        MessageBox.Show("用户名或密码错误");

                        dr.Close();

                        con.Close();

                    }

                }

                catch (Exception err)

                {

                    Response.Write(err);

                }

 

原创粉丝点击