SqlHelper的使用与DataSet-SqlDataAdapter

 1 try
 2             {
 3                 string sUsername = TextUserName.Text.Trim();
 4                 string sPwd = TextBoxPwd.Text.Trim();
 5                 if(string.IsNullOrEmpty(sUsername) || string.IsNullOrEmpty(sPwd))
 6                 {
 7                     Response.Write(@"<script>alert(""No Username or no Password..."");</script>");
 8                 }
 9                 else
10                 {
11                     string sSql = "select count(*) from UserInfor where UserName=@UserName and Pwd=@Pwd";
12                     SqlParameter[] paras = new SqlParameter[] {
13                         new SqlParameter("@UserName",sUsername),
14                         new SqlParameter("@Pwd",sPwd)
15                         };
16                     if(SqlHelper.Exists(sSql,paras))
17                     {
18                         Response.Redirect("UserM.aspx");
19                     }
20                     else
21                     {
22                         Response.Write(@"<script>alert(""Username or Password is Wrong! "");</script>");
23                     }
24                 }
25             }
26             catch 
27             {
28                 Response.Write(@"<script>alert(""The WebSite is under repairing..."");</script>");
29             }
View Code
 1 string connStr = ConfigurationManager.ConnectionStrings["sq_ruanmou"].ToString();
 2         DataSet ds = new DataSet();
 3         protected void Page_Load(object sender, EventArgs e)
 4         {
 5             SqlConnection con = new SqlConnection(connStr);
 6             string s = "select * from UserInfor";
 7             using (SqlCommand cmd = new SqlCommand(s, con))
 8             {
 9                 SqlDataAdapter ad = new SqlDataAdapter(cmd);
10                 ad.Fill(ds);
11                 DataTable dt = ds.Tables[0];
12                 GridView1.DataSource = dt;
13                 GridView1.DataBind();
14             }
15         }

 

posted @ 2017-02-17 18:15  ~Jungle  Views(223)  Comments(0Edit  收藏  举报