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


C# DB.Open方法代码示例

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


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

示例1: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        ErrorLabel.Text = "";
        int i = 0;
        using (SqlConnection conn = new DB().GetConnection())
        {
            string sql = "Update [ResourceFolders] set [email protected] where ID = @FolderID";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@FolderName", FolderName.Text.Trim());
            cmd.Parameters.AddWithValue("@FolderID", LabelFolderID.Text);
            conn.Open();
            i = cmd.ExecuteNonQuery();
            conn.Close();
            //将在Resources表中放在文件夹下的资源都更新文件夹名
            {
                sql = "Update Resources set [email protected] where FolderID = @FolderID";
                cmd.CommandText = sql;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                cmd.Dispose();
            }
        }

        if (i == 1)
        {
            ErrorLabel.Text = "媒体信息更新成功!";
            Response.Redirect(Server.HtmlEncode("Folder_Man.aspx"));
        }
        else
        {
            ErrorLabel.Text = "媒体信息更新失败,请重试!";
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:34,代码来源:Folder_Edit.aspx.cs

示例2: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        string sqlCon = "";
        using (SqlConnection conn = new DB().GetConnection())
        {
            SqlCommand cmd = conn.CreateCommand();
            // 删除物理路径下的文件
            {
                sqlCon = "Select * from Resources where ID in (" + IDSLabel.Text + ")";
                cmd.CommandText = sqlCon;
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "FileName");
                foreach (DataRow drow in ds.Tables["FileName"].Rows)
                {
                    string FilePath = drow["FilePath"].ToString();
                    // 删除物理路径下的文件
                    System.IO.File.Delete(Server.MapPath(FilePath));
                }
                conn.Close();
            }
            {
                sqlCon = "Delete from Article_Resource where ResourceID in (" + IDSLabel.Text + ")";
                cmd.CommandText = sqlCon;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

                sqlCon = "Delete from Resources where ID in (" + IDSLabel.Text + ")";
                cmd.CommandText = sqlCon;
                conn.Open();
                i = cmd.ExecuteNonQuery();
                cmd.Dispose();
                conn.Close();
            }

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

示例3: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = 0;
        string sqlCon = "";
        using (SqlConnection conn = new DB().GetConnection())
        {

            SqlCommand cmd = conn.CreateCommand();
            sqlCon = "select * from ResourceFolders where FolderName = @FolderName";
            cmd.CommandText = sqlCon;
            cmd.Parameters.AddWithValue("@FolderName", FolderName.Text);
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            cmd.Dispose();
            if (!rd.Read())
            {
                conn.Close();
                //向resources插入一条记录操作
                StringBuilder sb = new StringBuilder("Insert into ResourceFolders (FolderName,FolderType,UserID,CDT,Orders,Resources,ParentFolderID,IsSharedFolder,FoldGUID,Counts)");
                sb.Append(" values(@FolderName,@FolderType,@UserID,@CDT,@Orders,@Resources,@ParentFolderID,@IsSharedFolder,@FoldGUID,@Counts)");
                cmd = new SqlCommand(sb.ToString(), conn);
                cmd.Parameters.AddWithValue("@FolderName", FolderName.Text);
                cmd.Parameters.AddWithValue("@FolderType", "");
                cmd.Parameters.AddWithValue("@UserID", Session["UserID"].ToString());
                cmd.Parameters.AddWithValue("@CDT", DateTime.Now);
                cmd.Parameters.AddWithValue("@Orders", 1);
                cmd.Parameters.AddWithValue("@Resources", 0);
                cmd.Parameters.AddWithValue("@ParentFolderID", 0);
                cmd.Parameters.AddWithValue("@IsSharedFolder", 1);
                FoldGUID.Text = Guid.NewGuid().ToString();
                cmd.Parameters.AddWithValue("@FoldGUID", FoldGUID.Text);
                cmd.Parameters.AddWithValue("@Counts", 0);
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                //插入成功
                i = 1;
            }
            else
            {
                ErrorLabel.Text = "文件夹命名重复,请重新输入!";
            }
            rd.Close();
        }
        if (i == 1)
        {
            Response.Redirect(Server.HtmlEncode("Folder_Man.aspx"));
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:49,代码来源:Folder_Add.aspx.cs

示例4: 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

示例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 CatMenu order by Orders asc";
                        conn.Open();
                        SqlDataReader rd = cmd.ExecuteReader();
                        Cats.DataSource = rd;
                        Cats.DataValueField = "ID";
                        Cats.DataTextField = "CatMenuName";
                        Cats.DataBind();
                        rd.Close();
                    }
                }

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

示例6: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());

            if (Session["RoleID"] == null || Session["UserID"] == null)
            {
                Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
            }
            else if (RoleID > 1)
            {
                Util.ShowMessage("您没有访问该页面的权限!", "Login2.aspx");
            }
                else
                {

                    using (SqlConnection conn = new DB().GetConnection())
                    {
                        string sql = "select * from UserUtil_Notes order by ID desc";
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        conn.Open();
                        SqlDataReader rd = cmd.ExecuteReader();
                        GridView1.DataSource = rd;
                        GridView1.DataBind();
                        rd.Close();
                       conn.Close();
                    }
                    ChangePages();

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

示例7: 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 SubMenu where ID in (" + IDSLabel.Text + ") ";
            conn.Open();
            i = cmd.ExecuteNonQuery();
            cmd.Dispose();

            cmd.CommandText = "select * from SubMenu 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 = "成功删除!";
            ResultLabel.ForeColor = System.Drawing.Color.Green;

        }
        else
        {
            ResultLabel.Text = "操作失败,请重试!";
            ResultLabel.ForeColor = System.Drawing.Color.Red;
        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:31,代码来源:SubMenu_Del.aspx.cs

示例8: 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

示例9: 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

示例10: 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

示例11: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int RoleID = Convert.ToInt16(Session["RoleID"].ToString());

            if (Session["RoleID"] == null || Session["UserID"] == null)
            {
                Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
            }
            else if (RoleID > 1)
            {
                Util.ShowMessage("您没有访问该页面的权限!", "Login2.aspx");
            }
          else
          {
          UserName.Focus();
          using (SqlConnection conn = new DB().GetConnection())
          {
            string sql1 = "select * from Roles order by ID asc";
            SqlCommand cmd1 = new SqlCommand(sql1, conn);
            conn.Open();
            SqlDataReader rd1 = cmd1.ExecuteReader();
            Role.DataSource = rd1;
            Role.DataTextField = "RoleName";
            Role.DataValueField = "ID";
            Role.DataBind();
            rd1.Close();
          }
            }

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

示例12: Add_Click

    protected void Add_Click(object sender, EventArgs e)
    {
        //有输入文件名,在ResourceFolders插入一条记录
        if (!String.IsNullOrEmpty(FolderName.Text))
        {
            string folderType = Request.QueryString["type"];
            string UserID = Session["UserID"].ToString();
            string guid = System.Guid.NewGuid().ToString();
            using (SqlConnection conn = new DB().GetConnection())
            {
                StringBuilder sb = new StringBuilder("Insert into ResourceFolders(FolderName,FolderType,UserID,CDT,Orders,Resources,ParentFolderID,IsSharedFolder,FoldGUID)");
                sb.Append(" values(@FolderName,@FolderType,@UserID,@CDT,@Orders,@Resources,@ParentFolderID,@IsSharedFolder,@FoldGUID)");
                SqlCommand cmd = new SqlCommand(sb.ToString(),conn);
                conn.Open();
                cmd.Parameters.AddWithValue("@FolderName", FolderName.Text);
                cmd.Parameters.AddWithValue("@FolderType",folderType);
                cmd.Parameters.AddWithValue("@UserID",UserID);
                cmd.Parameters.AddWithValue("@CDT",DateTime.Now);
                cmd.Parameters.AddWithValue("@Orders",1);
                cmd.Parameters.AddWithValue("@Resources",0);
                cmd.Parameters.AddWithValue("@ParentFolderID",0);
                cmd.Parameters.AddWithValue("@IsSharedFolder",0);
                cmd.Parameters.AddWithValue("@FoldGUID",guid);
                cmd.ExecuteNonQuery();
            }
        }
        else
        {

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

示例13: 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

示例14: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["RoleID"] == null || Session["UserID"] == null)
            {
                Util.ShowMessage("用户登录超时,请重新登录!", "Login2.aspx");
            }
            else
            {
                LabelResourceID.Text = Request.QueryString["ID"];
                using (SqlConnection conn = new DB().GetConnection())
                {
                    string sql = "Select * from [Resources] where ID = @ResourceID";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    conn.Open();
                    cmd.Parameters.AddWithValue("@ResourceID", LabelResourceID.Text);
                    SqlDataReader rd = cmd.ExecuteReader();
                    if (rd.Read())
                    {
                        FileType.Text = rd["FileType"].ToString();
                        string resourcefolderID = rd["FolderID"].ToString();
                        if (FileType.Text.Equals("图片"))
                        {
                            Image1.ImageUrl = rd["FilePath"].ToString();
                        }
                        if (FileType.Text.Equals("压缩"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/ys.png";
                        }
                        if (FileType.Text.Equals("文档"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/wd.png";
                        }
                        if (FileType.Text.Equals("视频"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/sp.png";
                        }
                        if (FileType.Text.Equals("音频"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/yp.png";
                        }
                        if (FileType.Text.Equals("Flash"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/fl.png";
                        }
                        if (FileType.Text.Equals("附件"))
                        {
                            Image1.ImageUrl = "upload/Resource_Preview/wd.png";
                        }
                    }
                }
            }

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

示例15: iBoxTestCreateDbTest

 public void iBoxTestCreateDbTest()
 {
     var path = "ibox";
     if (!Directory.Exists(path))
         Directory.CreateDirectory(path);
     using (var server = new DB(path)){
         var db = server.Open ();
         Assert.IsTrue (db != null);
     }
 }
开发者ID:ss22219,项目名称:Booker,代码行数:10,代码来源:iBoxTest.cs


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