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


C# DBConnector.ExecuteNonQuery方法代码示例

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


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

示例1: ButtonCommit_Click

 protected void ButtonCommit_Click(object sender, EventArgs e)
 {
     //评论字数不能过小
     if (TextBoxComment.Text.Length < 5)
     {
         Helper.MsgBox("请至少输入五个字");
     }
     else
     {
         //插入评论记录
         DBConnector db = new DBConnector();
         String strSql = String.Format("Insert into Comments(CommenterId, FileMD5, CommentTime, Comment) Values({0}, '{1}', '{2}', '{3}')", Helper.UserId,
             StrMd5, DateTime.Now.ToString(), TextBoxComment.Text);
         db.ExecuteNonQuery(strSql);
         //增加文件的评论数
         strSql = String.Format("update Files set CommentCount = (Select CommentCount from Files where MD5='{0}') + 1 where MD5 = '{0}'", StrMd5);
         db.ExecuteNonQuery(strSql);
         //Helper.MsgBox("添加成功");
         //清空输入评价文本框
         TextBoxComment.Text = "";
         //显示评价
         ShowComments();
     }
 }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:24,代码来源:ViewFile.aspx.cs

示例2: ButtonDelete_Click

 protected void ButtonDelete_Click(object sender, EventArgs e)
 {
     //修改是否已删除为“是”
     //删除文件
     //跳转到主页
     DBConnector db = new DBConnector();
     db.ExecuteNonQuery("Update Files set IdDeleted = 1 where MD5 = '" + StrMd5 + "'");
     try
     {
         System.IO.File.Delete(Server.MapPath(StrFilePathName));
     }
     catch (System.Exception ex)
     {
         Helper.MsgBox("删除文件错误", ".\\Default.aspx");
     }
     Helper.MsgBox("删除成功", ".\\Default.aspx");
 }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:17,代码来源:ViewFile.aspx.cs

示例3: ButtonUpload2_Click

 protected void ButtonUpload2_Click(object sender, EventArgs e)
 {
     String strMd5 = "";
     int iLength = 0;
     String strFileName = "";
     //如果上传控件已选择文件
     if (FileUpload1.HasFile)
     {
         strFileName = FileUpload1.FileName;
         //将文件上传到零时目录下
         FileUpload1.SaveAs(Server.MapPath(".\\Temp\\" + strFileName));
         //将文件读取到字符串
         String contents = File.ReadAllText(Server.MapPath(".\\Temp\\" + strFileName));
         //计算文件 MD5 值
         strMd5 = Helper.CalMD5(contents);
         //检查 MD5 是否在系统中存在,即文件是否重复。
         DBConnector db = new DBConnector();
         int n = (int)db.ExecuteObject("Select count(*) From Files Where MD5='" + strMd5 + "'");
         if (n > 0)
         {
             //如果重复,删除该文件
             File.Delete(Server.MapPath(".\\Temp\\" + strFileName));
             Helper.MsgBox("系统中已存在该文件", "./ViewFile.aspx?MD5=" + strMd5);
         }
         else//否则
         {
             //将文件移动到上传目录下
             File.Move(Server.MapPath(".\\Temp\\" + strFileName), Server.MapPath(".\\Uploads\\" + strFileName));
             //计算文件长度
             iLength = FileUpload1.PostedFile.ContentLength;
             //插入文件记录
             String strSql = String.Format("Insert into Files (MD5, Title, Brief, Size, Point, UploadTime, UploaderId, FilePath, FileName)" +
                 " Values('{0}', '{1}', '{2}', {3}, {4}, '{5}', {6}, '.\\Uploads\\', '{7}')", strMd5,
                 TextBoxTitle.Text, TextBoxBrief.Text, iLength, TextBoxPoint.Text, DateTime.Now.ToString(),
                 Helper.UserId, strFileName);
             db.ExecuteNonQuery(strSql);
             Helper.MsgBox("上传成功", "./ViewFile.aspx?MD5=" + strMd5);
         }
     }
 }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:40,代码来源:Upload.aspx.cs

示例4: ButtonAddUser_Click

    protected void ButtonAddUser_Click(object sender, EventArgs e)
    {
        //1、检查学号是否已存在
        String strSql = String.Format("Select Count(*) From Users Where ID = '{0}'", TextBoxUserId.Text);
        DBConnector db = new DBConnector();

        if ((Int32)db.ExecuteObject(strSql) != 0 )
        {
            Helper.MsgBox("该用户已存在");
            return;
        }
        else
        {
            //是否管理员
            Int32 iIsAdmin;
            if (CheckBoxIsAdmin.Checked == true)
            {
                iIsAdmin = 1;
            }
            else
            {
                iIsAdmin = 0;
            }

            strSql = String.Format(@"Insert Into Users(ID, Pwd, Name, ClassId, Point, AddTime, IsAdmin, IsDeleted)
                Values({0}, '{1}', '{2}', {3}, 0, '{4}', {5}, 0)", TextBoxUserId.Text, Helper.CalMD5(TextBoxPwd.Text),
                TextBoxName.Text, DropDownListClass.SelectedIndex, DateTime.Now, iIsAdmin);
            if (db.ExecuteNonQuery(strSql) == true)
            {
                Helper.MsgBox("添加失败");
            }
            else
            {
                Helper.MsgBox("添加成功", "Default.aspx");
            }
        }
    }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:37,代码来源:AddUser.aspx.cs

示例5: ButtonDownload_Click

 protected void ButtonDownload_Click(object sender, EventArgs e)
 {
     //如果下载地址为空
     if (StrFilePathName == null)
     {
         Helper.MsgBox("下载地址错误");
         return;
     }
     DBConnector db = new DBConnector();
     //增加文件的下载数
     String strSql = "Update Files set DownloadCount = (Select DownloadCount From Files Where MD5='" + StrMd5 +
                     "') + 1 Where MD5='" + StrMd5 + "'";
     db.ExecuteNonQuery(strSql);
     //插入下载记录
     strSql = "Insert Into Downloads(DownloaderId, FileMd5, DownloadTime) values(" + "61287, '" +
         StrMd5 + "', '" + System.DateTime.Now + "')";
     db.ExecuteNonQuery(strSql);
     //减少下载者的积分
     strSql = "Update Users set Point = (Select Point From Users Where ID=" + Helper.UserId + ") - " + IFilePoint +
         " where ID=" + Helper.UserId;
     db.ExecuteNonQuery(strSql);
     //增加上传者的积分
     strSql = "Update Users set Point = (Select Point From Users Where ID=" + IUploaderId + ") + " + IFilePoint +
         " where ID=" + IUploaderId;
     db.ExecuteNonQuery(strSql);
     Response.Redirect(StrFilePathName);
 }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:27,代码来源:ViewFile.aspx.cs

示例6: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Helper.UserId == 0)
        {
            ButtonDownload.Enabled = false;
        }
        if (!IsPostBack)
        {
            //获取下载地址
            if (Request.QueryString["MD5"] != null)
            {
                StrMd5 = Request.QueryString["MD5"];

                String strSql = "Select UploaderId, FilePath, FileName, Point From Files Where MD5='"
                    + Request.QueryString["MD5"] + "'";
                DBConnector db = new DBConnector();
                using (SqlDataReader dr = db.ExecuteReader(strSql))
                {
                    while (dr.Read())
                    {
                        StrFilePathName = dr.GetString(1) + dr.GetString(2);
                        IUploaderId = dr.GetInt32(0);
                        IFilePoint = dr.GetInt32(3);
                    }
                    dr.Close();
                }
                //如果不是管理员或者上传者,应取消编辑和删除按钮,取消下载记录
                if (!(Helper.IsAdmin || IUploaderId == Helper.UserId))
                {
                    ButtonEdit.Visible = false;
                    ButtonDelete.Visible = false;
                    GridViewDownload.Visible = false;
                    LabelDownloads.Visible = false;
                }
                else
                {
                    ButtonEdit.Visible = true;
                    ButtonDelete.Visible = true;
                    GridViewDownload.Visible = true;
                    LabelDownloads.Visible = true;
                }

                //增加下载次数
                strSql = "Update Files set ViewCount = (Select ViewCount From Files Where MD5='" + StrMd5 +
                    "') + 1 Where MD5='" + StrMd5 + "'";

                db.ExecuteNonQuery(strSql);

                ShowComments();
            }
            else
            {
                Response.Redirect("Default.aspx");
            }

        }
    }
开发者ID:dalinhuang,项目名称:zhaoxiang,代码行数:57,代码来源:ViewFile.aspx.cs

示例7: UpdateInfoWithKey

 public static int UpdateInfoWithKey(string key, string newInfo, DBConnector connector)
 {
     var commandQuery = string.Format("{0} {1} = '{2}' WHERE {3} = '{4}'", CommandBuilder.InitUpdateStatement(Constants.StatusTableName), Constants.ValueColumn, newInfo, Constants.StatusColumn, key);
     SqlCommand command = new SqlCommand(commandQuery);
     return connector.ExecuteNonQuery(command);
 }
开发者ID:ethantang95,项目名称:HackRPI,代码行数:6,代码来源:InfoRequest.cs


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