当前位置: 首页>>代码示例>>C#>>正文


C# DB.CreateCommand方法代码示例

本文整理汇总了C#中DB.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DB.CreateCommand方法的具体用法?C# DB.CreateCommand怎么用?C# DB.CreateCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "Delete from ArticleTags where ID in (" + IDSLabel.Text + ") ";
            SqlCommand cmd1 = conn.CreateCommand();
            cmd1.CommandText = "Delete from Articles_ArticleTags where ArticleTagID in (" + IDSLabel.Text + ") ";

            conn.Open();
            cmd1.ExecuteNonQuery();
            i = cmd.ExecuteNonQuery();
            cmd.Dispose();
            cmd1.Dispose();

            cmd.CommandText = "select * from ArticleTags where ID in (" + IDSLabel.Text + ") order by ID desc";
            SqlDataReader rd = cmd.ExecuteReader();
            GridView1.DataSource = rd;
            GridView1.DataBind();
            rd.Close();
            conn.Close();

        }
        if (i > 0)
        {
            ResultLabel.Text = "成功删除" + i + "个标签!";
            ResultLabel.ForeColor = System.Drawing.Color.Green;
        }
        else
        {
            ResultLabel.Text = "操作失败,请重试!";
            ResultLabel.ForeColor = System.Drawing.Color.Red;
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:35,代码来源:ArticleTag_Del.aspx.cs

示例2: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
          using (SqlConnection conn = new DB().GetConnection())
          {
              SqlCommand cmd = conn.CreateCommand();
              cmd.CommandText = "Delete from Users where ID in (" + IDSLabel.Text + ") ";
              SqlCommand cmd1 = conn.CreateCommand();
              cmd1.CommandText = "Delete from Users_UserTags where UserID in (" + IDSLabel.Text + ") ";
              conn.Open();
              i = cmd.ExecuteNonQuery();
              cmd1.ExecuteNonQuery();
              cmd.Dispose();
              cmd1.Dispose();

              cmd.CommandText = "select * from Users where ID in (" + IDSLabel.Text + ") order by ID desc";
              SqlDataReader rd = cmd.ExecuteReader();
              GridView1.DataSource = rd;
              GridView1.DataBind();
              rd.Close();
              conn.Close();
          }
          if (i > 0)
          {
              string deleteUserName = "个用户,分别为“" + DeleteUserName.Text + " ”" ;
              Util.UserUtil_Notes("成功删除了", i, deleteUserName, UserName.Text, "User_Del.aspx", UserIP.Text);
              ResultLabel.Text = "成功删除" + i + "个用户!";
              ResultLabel.ForeColor = System.Drawing.Color.Green;
          }
          else
          {
              ResultLabel.Text = "操作失败,请重试!";
              ResultLabel.ForeColor = System.Drawing.Color.Red;
          }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:35,代码来源:User_Del.aspx.cs

示例3: Any

		public object Any (LatestBuilds request)
		{
			var result = new List<KeyValuePair<DBHost, DBRevisionWorkView2>> ();
			List<DBLane> lanes = null;
			var hostLanes = new List<DBHostLane> ();

			using (DB db = new DB ()) {
				lanes = db.GetAllLanes ();

				using (IDbCommand cmd = db.CreateCommand ()) {
					cmd.CommandText = @"
SELECT HostLane.*
FROM HostLane
WHERE hidden = false";
					
					using (IDataReader reader = cmd.ExecuteReader ())
						while (reader.Read ())
							hostLanes.Add (new DBHostLane (reader));
				}

				foreach (DBHostLane hl in hostLanes) {
					DBRevisionWorkView2 revisionWork = null;
					using (IDbCommand cmd = db.CreateCommand ()) {
						cmd.CommandText = @"SELECT R.* FROM (" + DBRevisionWorkView2.SQL.Replace (';', ' ') + ") AS R WHERE R.host_id = @host_id AND R.lane_id = @lane_id LIMIT @limit";
						DB.CreateParameter (cmd, "host_id", hl.host_id);
						DB.CreateParameter (cmd, "lane_id", hl.lane_id);
						DB.CreateParameter (cmd, "limit", 1);
						
						using (IDataReader reader = cmd.ExecuteReader ())
							while (reader.Read ())
								revisionWork = new DBRevisionWorkView2 (reader);
					}

					result.Add (new KeyValuePair<DBHost, DBRevisionWorkView2> (Utils.FindHost (db, revisionWork.host_id), revisionWork));
				}
			}

			var list = result.Where (view => view.Value != null).Select (view => {
				var item = view.Value;
				var lane = lanes.Where (l => l.id == item.lane_id).FirstOrDefault ();
				var parent = Utils.GetTopMostParent (lane, lanes);
				return new Build {
					Commit = item.revision,
					CommitId = item.revision_id,
					Date = item.completed ? item.endtime : item.date,
					Lane = lane.lane,
					LaneID = lane.id,
					Project = parent.lane,
					State = item.State,
					Author = item.author,
					BuildBot = view.Key == null ? string.Empty : view.Key.host,
					HostID = item.host_id,
					Url = Utils.MakeBuildUrl (item.lane_id, item.host_id, item.revision_id)
				};
			}).OrderByDescending (b => b.Date).ToList ();

			return new LatestBuildsResponse {
				LatestBuilds = list
			};
		}
开发者ID:vargaz,项目名称:monkeywrench,代码行数:60,代码来源:LatestBuilds.cs

示例4: getWorkInfo

		/**
		 * Fetches info needed from the database.
		 */
		private RevisionWorkInfo getWorkInfo(DB db, int revisionWorkID, int workID) {
			using (var cmd = db.CreateCommand ()) {
				cmd.CommandText = @"
					SELECT revision.revision, lane.id, lane.repository, lane.lane
					FROM revisionwork
					INNER JOIN revision ON revision.id = revisionwork.revision_id
					INNER JOIN lane ON lane.id = revision.lane_id
					WHERE revisionwork.id = @rwID;

					SELECT command.command
					FROM work
					INNER JOIN command ON command.id = work.command_id
					WHERE work.id = @wID
				";
				DB.CreateParameter (cmd, "rwID", revisionWorkID);
				DB.CreateParameter (cmd, "wID", workID);
				using (var reader = cmd.ExecuteReader ()) {
					RevisionWorkInfo info;

					reader.Read ();

					info.hash = reader.GetString (0);
					info.laneID = reader.GetInt32 (1);
					info.repoURL = reader.GetString (2);
					info.laneName = reader.GetString (3);

					reader.NextResult ();
					reader.Read ();

					info.command = reader.GetString (0);

					return info;
				}
			}
		}
开发者ID:joewstroman,项目名称:monkeywrench,代码行数:38,代码来源:GitHubNotification.cs

示例5: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["RoleID"] == null || Session["UserID"] == null)
            {
                Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
            }
            else
            {
                 int RoleID = Convert.ToInt16(Session["RoleID"].ToString());
                if (RoleID > 1)
                {
                    Util.ShowMessage("对不起,你无权访问该页面!", "User_Center.aspx");

                }
                else
                {
                    using (SqlConnection conn = new DB().GetConnection())
                    {
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "select * from Cats order by Orders desc";
                        conn.Open();
                        SqlDataReader rd = cmd.ExecuteReader();
                        Cats.DataSource = rd;
                        Cats.DataValueField = "ID";
                        Cats.DataTextField = "CatName";
                        Cats.DataBind();
                        rd.Close();
                    }
                }
            }
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:34,代码来源:Sub_Add.aspx.cs

示例6: CheckExtension

    // 判断fileextension是否合法
    protected bool CheckExtension(string extension)
    {
        bool result = false;
        // 如果Dictionary的键值数<1,即没有元素,则先读取数据表
        if (ResourceTypes.Keys.Count < 1)
        {
            using (SqlConnection conn = new DB().GetConnection())
            {
                SqlDataReader rd;
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select * from ResourceTypes";
                conn.Open();
                rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    ResourceTypes.Add(rd["Extension"].ToString(), rd["TypeName"].ToString());
                }
                rd.Close();
                conn.Close();
            }

        }
        // 判断是否含有指定的后缀名
        if (ResourceTypes.ContainsKey(extension))
        {
            result = true;
            ResourceTypeLabel.Text = ResourceTypes[extension];
        }
        return result;
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:31,代码来源:File_Browse.aspx.cs

示例7: MyDataBind

    protected void MyDataBind()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            SqlDataReader rd;
            cmd.CommandText = "select * from Users where ID= " + UserIDLabel.Text;
            conn.Open();
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                UserNameLabel.Text = rd["UserName"].ToString();
                BigNameLabel.Text = rd["UserName"].ToString();
            }
            rd.Close();

            cmd.CommandText = "select * from Profiles where UserID = " + UserIDLabel.Text + " order by ID desc";
            rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                if(!String.IsNullOrEmpty(rd["BigName"].ToString())){
                    BigNameLabel.Text = rd["BigName"].ToString();
                }
                BigImage.ImageUrl = rd["BigPhotoSrc"].ToString();
                IntroductionLabel.Text = rd["Introduction"].ToString();
                BoxTop.Text = rd["BoxTop"].ToString();
                BoxLeft.Text = rd["BoxLeft"].ToString();
                BoxHeight.Text = rd["BoxHeight"].ToString();
                BoxWidth.Text = rd["BoxWidth"].ToString();
                BoxOpacity.Text = rd["BoxOpacity"].ToString();
            }
            rd.Close();
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:34,代码来源:User_Profile.aspx.cs

示例8: like1_Click

 protected void like1_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(Request.QueryString["ID"]))
     {
         using (SqlConnection conn = new DB().GetConnection())
         {
             SqlCommand cmd = conn.CreateCommand();
             cmd.CommandText = "select * from [ArticleView_Like] where [UserIP] = @UserIP and [ArticleID][email protected] and [LikeDate][email protected] and [UserID] = @UserID";
             cmd.Parameters.AddWithValue("@UserIP", USERIP);
             cmd.Parameters.AddWithValue("@UserID", (User_id.Text == "" ? "Null" : User_id.Text));
             cmd.Parameters.AddWithValue("@ArticleID", int.Parse(ArticleID.Text));
             cmd.Parameters.AddWithValue("@LikeDate", DateTime.Now.ToString("yyyy-MM-dd"));
             conn.Open();
             SqlDataReader rd = cmd.ExecuteReader();
             if (rd.Read()) { Response.Write("<script>alert('您今天已经点过赞了');</script>"); }
             else
             {
                 cmd.CommandText = "Insert into ArticleView_Like (ArticleID,UserIP,LikeDate,UserID)values(@ArticleID,@UserIP,@LikeDate,@UserID)";
                 rd.Close();
                 cmd.ExecuteNonQuery();
                 likeCount1.Text = (Convert.ToInt32(likeCount1.Text) + 1).ToString();
                 like1.Style["background-position"] = "right";
                 like1.Enabled = false;
                 LikeTimes.Text = (Convert.ToInt32(LikeTimes.Text) + 1).ToString();
             }
             rd.Close();
         }
     }
 }
开发者ID:ZRUIK,项目名称:SETC,代码行数:29,代码来源:Article_View2.aspx.cs

示例9: MyInit

    private void MyInit()
    {
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            SqlDataReader rd = null;
            string CategoryID = "0";
            cmd.CommandText = "select ID,Description,Subs,IsShow from Cats where CatName = @CatName";
            cmd.Parameters.AddWithValue("@CatName", CategoryLabel.Text);
            conn.Open();
            rd = cmd.ExecuteReader();

            int subs = 0;
            if (rd.Read())
            {
                CategoryID = rd["ID"].ToString();
                CategoryIDLabel.Text = CategoryID;
                DescriptionLabel.Text = rd["Description"].ToString();
                subs = Convert.ToInt16(rd["Subs"]);
            }
            rd.Close();

            cmd.CommandText = "select ID,SubName,CatName from Subs where Valid = 1 and CatID = " + CategoryID + " Order By Orders Desc";
            rd = cmd.ExecuteReader();
            Repeater2.DataSource = rd;
            Repeater2.DataBind();
            rd.Close();

        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:30,代码来源:Article_Roster_List.aspx.cs

示例10: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        string Count = "0";
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select count(*) as Count from Articles where [email protected]";
            cmd.Parameters.AddWithValue("@SubID", IDSLabel.Text);
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                Count = rd["Count"].ToString();
            }
            rd.Close();

            if (Count == "0")
            {
                Del();
            }
            else
            {
                Response.Write("<script>alert(' 操作失败!! \\n  \\n 该栏目下仍存在文章,请删除该栏目下的文章后,才能对栏目进行删除!')</script>");
            }

            conn.Close();
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:28,代码来源:Sub_Del.aspx.cs

示例11: LoginUser

		/// <summary>
		/// Returns null if login failed.
		/// </summary>
		/// <param name="db"></param>
		/// <param name="user"></param>
		/// <param name="password"></param>
		/// <returns></returns>
		public static DBLogin LoginUser (DB db, string login, string password, string ip4, bool @readonly)
		{
			DBLogin result;
			int id;

			using (IDbCommand cmd = db.CreateCommand ()) {
				// TODO: Encrypt passwords somehow, not store as plaintext.
				cmd.CommandText = "SELECT id FROM Person WHERE login = @login AND password = @password;";
				DB.CreateParameter (cmd, "login", login);
				DB.CreateParameter (cmd, "password", password);
				using (IDataReader reader = cmd.ExecuteReader ()) {
					if (!reader.Read ())
						return null;

					id = reader.GetInt32 (0);

					//if (reader.Read ())
					//	return null;
				}
			}

			result = new DBLogin ();
			result.person_id = id;
			result.ip4 = ip4;

			if ([email protected]) {
				result.expires = DateTime.Now.AddDays (1);
				result.cookie = CreateCookie ();

				result.Save (db);
			}

			return result;
		}
开发者ID:MSylvia,项目名称:monkeywrench,代码行数:41,代码来源:DBLogin_Extensions.cs

示例12: Logout

		public static void Logout (DB db, string cookie)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "DELETE FROM Login WHERE cookie = @cookie;";
				DB.CreateParameter (cmd, "cookie", cookie);
				cmd.ExecuteNonQuery ();
			}
		}
开发者ID:rolfbjarne,项目名称:monkeywrench,代码行数:8,代码来源:DBLogin_Extensions.cs

示例13: AddLane

		public static void AddLane (this DBHost me, DB db, int lane_id)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "INSERT INTO HostLane (host_id, lane_id) VALUES (@host_id, @lane_id);";
				DB.CreateParameter (cmd, "host_id", me.id);
				DB.CreateParameter (cmd, "lane_id", lane_id);
				cmd.ExecuteNonQuery ();
			}
		}
开发者ID:joewstroman,项目名称:monkeywrench,代码行数:9,代码来源:DBHost_Extensions.cs

示例14: RemoveLane

		public static void RemoveLane (this DBHost me, DB db, int lane_id)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "DELETE FROM HostLane WHERE host_id = @host_id AND lane_id = @lane_id;";
				DB.CreateParameter (cmd, "host_id", me.id);
				DB.CreateParameter (cmd, "lane_id", lane_id);
				cmd.ExecuteNonQuery ();
			}
		}
开发者ID:joewstroman,项目名称:monkeywrench,代码行数:9,代码来源:DBHost_Extensions.cs

示例15: RemoveEmail

		public static void RemoveEmail (this DBPerson person, DB db, string email)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "DELETE FROM UserEmail WHERE person_id = @person_id AND email = @email;";
				DB.CreateParameter (cmd, "person_id", person.id);
				DB.CreateParameter (cmd, "email", email);
				cmd.ExecuteNonQuery ();
			}
		}
开发者ID:joewstroman,项目名称:monkeywrench,代码行数:9,代码来源:DBPerson_Extensions.cs


注:本文中的DB.CreateCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。