日期:2014-05-17 浏览次数:20586 次
SqlCommand selectcmd1 = new SqlCommand(); selectcmd1.CommandText = "select logincount,UserName from Role"; selectcmd1.Connection = con; SqlCommand edit = new SqlCommand(); edit.CommandText = "updata Role set logincount=@logincount where UserName=@UserName "; edit.Connection = con; da.SelectCommand = selectcmd1; da.Fill(ds1, "Role"); //DataRow row = ds1.Tables["Role"].Rows[0]; //Session["name"] = row[0]; DataRow editdr = null; foreach (DataRow dr1 in ds1.Tables["Role"].Rows) { if (dr1[1].ToString() == Login1.UserName) { editdr = dr1; break; } } editdr["logincount"] = int.Parse(editdr["logincount"].ToString()) + 1; SqlParameter sp = new SqlParameter("@logincount", SqlDbType.Int, 4); SqlParameter sp1 = new SqlParameter("@UserName", SqlDbType.VarChar, 50); sp.Value = int.Parse(editdr["logincount"].ToString()); sp1.Value = Login1.UserName; edit.Parameters.Add(sp); edit.Parameters.Add(sp1); da.UpdateCommand = edit; //edit.Parameters.Add("@logincount", SqlDbType.Int, 4, "logincount").Value=editdr["logincount"];//Session["name"]=editdr["logincount"]; da.Update(ds1, "Role"); con.Close(); Login1.DestinationPageUrl = "~/Main.aspx";