2007年6月5日星期二

2007年6月5日 星期二

装了个vs.net2005好些天了,今天做了个登录页面的练习,捣鼓了半天,又问人又查帮助的,呵呵,

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
         protected void Page_Load(object sender, EventArgs e)
         {

         }
         protected void btnLogin_Click(object sender, EventArgs e)
         {
             string userName = this.tbUserName.Text;
             string pwd = this.tbPwd.Text;
             string sql = "select * from tb_user where id='" + userName + "' and passwd='" + pwd + "'";

             String url = ConfigurationManager.ConnectionStrings["csConnectionString"].ConnectionString;


             DataSet dataSet = new DataSet("user");
             using (SqlConnection connection = new SqlConnection(url))
             {
                 connection.Open();
                 SqlDataAdapter da = new SqlDataAdapter(sql, connection);
                 da.Fill(dataSet);
                 connection.Close();
             }

             if (dataSet.Tables[0].Rows.Count > 0)
             {
                 Response.Write("<script>alert('login success');</script>");
             }
             else
             {
                 Response.Write("<script>alert('login failed');</script>");
             }

         }
}

.net中数据适配器SqlDataAdapter 和数据集DataSet都不用关闭么?java中jdbc的Statement和ResultSet可都是要关的

终于捣鼓出来了

没有评论:

发表评论