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


C# SqlCommand.ExecuteNonQuery方法代码示例

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


在下文中一共展示了SqlCommand.ExecuteNonQuery方法的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: BtnDelete_Click

 private void BtnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("هل ترغب في الاستمرار؟", "تأكــــيد", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
     {
         return;
     }
     SqlTransaction Trn = null;
     using (SqlConnection Con = new SqlConnection(FXFW.SqlDB.SqlConStr))
     {
         SqlCommand Cmd = new SqlCommand(String.Format("DELETE FROM CustomersSuppliers WHERE (PERSONID = {0})", LUEItems.EditValue), Con);
         try
         {
             Con.Open();
             Trn = Con.BeginTransaction();
             Cmd.Transaction = Trn;
             Cmd.ExecuteNonQuery();
             if (CustomerTbl.Rows[LUEItems.ItemIndex]["AccountId"].ToString() != string.Empty)
             {
                 Cmd.CommandText = "DELETE FROM TBL_Accountes Where AccountId = " + CustomerTbl.Rows[LUEItems.ItemIndex]["AccountId"].ToString();
                 Cmd.ExecuteNonQuery();
             }
             Trn.Commit();
             LoadData();
             GetNewAccountID();
             LUEItems.ItemIndex = -1;
             MessageBox.Show("تم الحـــذف ", "حـــــذف", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             Trn.Rollback();
             MessageBox.Show(ex.Message);
         }
     }
 }
开发者ID:EgyFalseX,项目名称:Winform,代码行数:34,代码来源:EditorCustomerFrm.cs

示例3: UpdateEducationlDetail

    public bool UpdateEducationlDetail(UserDetails user)
    {
        try
        {
            SqlCommand com = new SqlCommand();
            com.Connection = DbManager.Con;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "SP_Update_Education_And_Profession";



            com.Parameters.AddWithValue("@Bride_Id", user.Id);
            com.Parameters.AddWithValue("@Groom_Id", user.Id);


            com.Parameters.AddWithValue("@Occupation", user.Occupation);
            com.Parameters.AddWithValue("@Profession_Id", user.Profession_Id);
            com.Parameters.AddWithValue("@Anual_Incom", user.Anual_Incom);
            com.Parameters.AddWithValue("@Educational_Qualification", user.Education);
            com.Parameters.AddWithValue("@Gender", user.Gender);

            DbManager.Open();
            com.ExecuteNonQuery();
            return Convert.ToBoolean(com.ExecuteNonQuery());

        }
        catch { throw; }
        finally
        {
            DbManager.Close();

        }

    }
开发者ID:vivek0tiwari,项目名称:shaadisaagai,代码行数:34,代码来源:DALProfile.cs

示例4: Run

        public static void Run()
        {
            using (SqlConnection con = new SqlConnection(Helper.GetCurrentDbConnectionString()))
            {
                using (SqlCommand cmd = new SqlCommand("Update_Table_ScheduledWork", con))
                {
                    string[] sqlfiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "App_Data\\SqlQueries");

                    con.Open();

                    // create user defined types before creating stored procedures
                    foreach (string file in sqlfiles.Where(f => f.Contains("Type_Table_Raw")))
                    {
                        cmd.CommandText = File.ReadAllText(file);
                        cmd.ExecuteNonQuery();
                    }

                    foreach (string file in sqlfiles.Where(f => f.Contains("StoredProcedure_BulkUpdate")))
                    {
                        cmd.CommandText = File.ReadAllText(file);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
开发者ID:ZiLinNZ,项目名称:GoAuckland,代码行数:25,代码来源:ExecuteAllSqlFiles.cs

示例5: ButtonSubmit_Click

    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        string CustId = Request.QueryString["CustId"];

        Connection con = new Connection();
        string strConnString = con.GetConnString();
        using (SqlConnection SqlCon = new SqlConnection(strConnString))
        {
            SqlCommand SqlComm = new SqlCommand("", SqlCon);
            SqlCon.Open();

            int ac_HolderId = Convert.ToInt32(CustId);
            decimal ac_Blnc = Convert.ToDecimal(TextBoxBlnc.Text);
            string ac_AltDate = DateTime.Now.ToString();

            string query = string.Format("INSERT INTO account(ac_cid, ac_type, ac_blnc, ac_date) VALUES('" + ac_HolderId + "', '" + DropDownListAcType.SelectedValue + "', '" + ac_Blnc + "', '" + ac_AltDate + "')");
            SqlComm.CommandText = query;
            SqlComm.ExecuteNonQuery();

            string SetStatus = string.Format("UPDATE cust_details SET c_status='1' WHERE c_id='" + ac_HolderId + "'");
            SqlComm.CommandText = SetStatus;
            SqlComm.ExecuteNonQuery();

            General GetNewCode = new General();
            string ChqRefNo = GetNewCode.GenerateCode();
            string Nartion = "Cash";
            string NowDate = DateTime.Now.ToString();

            string queryFrTrns = string.Format("INSERT INTO transactions(t_cid, t_nartion, t_refNo, t_deposit, t_blnc, t_date) VALUES('" + ac_HolderId + "', '" + Nartion + "', '" + ChqRefNo + "', '" + ac_Blnc + "', '" + ac_Blnc + "', '" + NowDate + "')");
            SqlComm.CommandText = queryFrTrns;
            SqlComm.ExecuteNonQuery();

            Response.Redirect("~/Admin/customer.aspx?CustId="+ CustId + "");
        }
    }
开发者ID:rkchauhan,项目名称:Net-Banking-in-DotNet-LW,代码行数:35,代码来源:customer.aspx.cs

示例6: registerBtn_Click

    protected void registerBtn_Click(object sender, EventArgs e)
    {
        string firstName, lastName, email, username, password, address, mobileNum;
        firstName = firstNameTxt.Text;
        lastName = lastNameTxt.Text;
        email = emailTxt.Text;
        username = usernameTxt.Text;
        password = passwordTxt.Text;
        address = addressTxt.Text;
        mobileNum = mobileNumTxt.Text;

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString);
        string valCmd = "select UserId,Email from UDetail";
        SqlCommand CMD = new SqlCommand(valCmd, con);
        con.Open();
        string cmd = "insert into UDetail values('" + firstName + "','" + lastName + "','" + username + "','" + password + "','" + address + "','" + mobileNum + "','" + email + "') ";
        SqlCommand Cmd = new SqlCommand(cmd, con);

        Cmd.ExecuteNonQuery();
        Cmd.CommandText = "insert into login values('" + username + "','" + password + "','user')";

        Cmd.ExecuteNonQuery();
        Response.Cookies["UserId"].Value = username;
        Response.Cookies["Pwd"].Value = password;
        //Response.Cookies["role"].Value = "user";
        FormsAuthentication.RedirectFromLoginPage(firstName, true);
        con.Close();
        Response.Redirect("register_success.aspx");
    }
开发者ID:kjeans,项目名称:online-shop,代码行数:29,代码来源:register.aspx.cs

示例7: btnSubmit_Click

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string recoverCode = !string.IsNullOrEmpty(Request.QueryString["RecoveryCode"])
        ? Request.QueryString["RecoveryCode"] : Guid.Empty.ToString();

        using (SqlConnection con = new SqlConnection(Helper.GetCon()))
        using (SqlCommand cmd = new SqlCommand())
        {
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "UPDATE Users SET [email protected] FROM Users " +
                "INNER JOIN Recover ON Users.UserID = Recover.UserID WHERE RecoveryCode" +
                "[email protected]";
            cmd.Parameters.AddWithValue("@recovercode", recoverCode);
            cmd.Parameters.AddWithValue("@Password", Helper.CreateSHAHash(txtPassword2.Text));
            cmd.ExecuteNonQuery();

            cmd.CommandText = "DELETE FROM Recover WHERE UserID=" +
                "(SELECT UserID FROM Users WHERE [email protected])";
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@recovercode", recoverCode);
            cmd.Parameters.AddWithValue("@email", txtEmail.Text);
            cmd.ExecuteNonQuery();

            success.Visible = true;
            error.Visible = false;
        }
    }
开发者ID:thegrassjelly,项目名称:Lifeline-CRM,代码行数:28,代码来源:CreateNewPassword.aspx.cs

示例8: DoCardSupply

        private bool DoCardSupply(string cardcode, string money)
        {
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
            conn.ConnectionString = rms_var.ConnStr;
            try
            {
                SqlCommand selectCMD = new SqlCommand();
                selectCMD.CommandTimeout = 30;
                conn.Open();
                selectCMD.Connection = conn;
                selectCMD.CommandText = "update clubcard set " + "remaincost=remaincost+" + NumericUpDown1.Text + " where clubcardno='" + cardcode + "'";
                selectCMD.ExecuteNonQuery();

                //记录该次充值记录
                selectCMD.CommandText = "insert into CardSupply " + "(clubcardno,supplydate,cost,operator) " + "values " + "(" + "'" + cardcode + "'" + "," + "'" + DateTime.Now.ToString() + "'" + "," + money + "," + "'" + rms_var.opinfo.OpID + "'" + ")";
                selectCMD.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
            finally
            {
                conn.Close();
            }
        }
开发者ID:uwitec,项目名称:carrey-rms,代码行数:28,代码来源:frmCardSupply.cs

示例9: Execute

 public override bool Execute()
 {
     var conn = SqlServerHelper.GetDatabaseConnection(DatabaseServer, DatabaseUserName, DatabasePassword);
     try
     {
         conn.Open();
         var cmd = new SqlCommand();
         cmd.Connection = conn;
         if (SqlServerHelper.DatabaseExists(conn, DatabaseName))
         {
             cmd.CommandText = String.Format(DropDatabase, DatabaseName);
             cmd.ExecuteNonQuery();
         }
         Log.LogMessage("Creating database {0} on {1}", DatabaseName, DatabaseServer);
         cmd.CommandText = String.Format("CREATE DATABASE {0}", DatabaseName);
         cmd.ExecuteNonQuery();
         return true;
     }
     catch (SqlException ex)
     {
         Log.LogErrorFromException(ex, true);
         return false;
     }
     finally
     {
         conn.Close();
     }
 }
开发者ID:jacderida,项目名称:JobSystem,代码行数:28,代码来源:CreateDatabase.cs

示例10: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(constring);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.Text;
        cmd.Connection = con;
        con.Open();
        cmd.CommandText = "insert into schedule(flightid,Flightname,Fromstation,Tostation,dateandtimings,Firstclass,Bussinessclass,economicclass) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" +TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')";

        int i = cmd.ExecuteNonQuery();
        cmd.CommandText = "insert into Fares(flightid,Flightname,Fromstation,Tostation,dateandtimings,firstclass,Bussinessclass,economicclass) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','"+TextBox5.Text+"','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "')";

         int j = cmd.ExecuteNonQuery();

         if (i >= 0 && j > 0)
         {
             Label.Visible = true;
             Label.Text = "sucessfully Added";
              }
         else
         {
             Label.Visible = true;
             Label.Text = "Error";
         }
    }
开发者ID:QualityThoughtTechnologies,项目名称:DotnetBatch2,代码行数:25,代码来源:Add+a+flight.aspx.cs

示例11: backgroundWorker_DoWork

        void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker backgroundWorker = sender as BackgroundWorker;
                backgroundWorker.ReportProgress(0, "instaling");
                using (SqlConnection con = e.Argument as SqlConnection)
                {
                    string comad1 = System.IO.File.ReadAllText("KillSQL.sql");
                    string comad2  = System.IO.File.ReadAllText("DeploySQL.sql");
                    int r;

                    SqlCommand sqlCommand = new SqlCommand(comad1, con);

                    con.Open();
                    r = sqlCommand.ExecuteNonQuery();

                    sqlCommand.CommandText = comad2;
                    r = sqlCommand.ExecuteNonQuery();

                    con.Close();
                }
            }
            catch (Exception ex)
            {
                e.Result = new Tuple<string, bool>("failed " + ex.Message, false);
                return;
            }
            e.Result = new Tuple<string,bool>("success", true );
        }
开发者ID:FuujinTheHacker,项目名称:LoM,代码行数:30,代码来源:InstalSqlTablesPage.xaml.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            string finduser;
            string r;
            string u;
            string s;
            SqlConnection con1 = Main.connection;
            con1.Close();
            con1.Open();
            string insert = "Insert Into[تاریخچه] ([شناسه کالا],[شناسه کارمند],[تاریخ],[توضیحات],[وضعیت]) Values (@id,@uid,@date,@ds,@status); ";
            SqlCommand command = new SqlCommand(insert, con1);
               // MessageBox.Show(hid);
            command.Parameters.Add("@id", AssetID.Text);
            command.Parameters.Add("@uid",fid);
            command.Parameters.Add("@date", DateTime.Now);
            command.Parameters.Add("@ds", Hist_Disc.Text);
            command.Parameters.Add("@status",Status_Hitory.Text);
            command.ExecuteNonQuery();
            con1.Close();

            string update = "Update کالا set وضعیت='"+Status_Hitory.Text+"'  where شناسه='"+AssetID.Text+"';";
            command.CommandText = update;
            con1.Open();
            command.ExecuteNonQuery();
            con1.Close();

            //

            MessageBox.Show("با موفقیت ثبت شد", "پیغام", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
开发者ID:uwitec,项目名称:Asset_Mng,代码行数:30,代码来源:Info.cs

示例13: btnConfirm_Click

 //「確定」按鈕事件
 protected void btnConfirm_Click(object sender, EventArgs e)
 {
     if (tbGroupName.Text != "") //判斷群組名稱是否為空
         if (tbGroupPsw.Text == tbGroupPswConfirm.Text) //判斷兩次輸入的密碼是否相同
         {
             //將建立的群組存入PushMessage_TempGroup資料表
             //clsHintsDB HintsDB = new clsHintsDB();
             try
             {
                 using (SqlConnection conn = new SqlConnection(strConnString))
                 {
                     using (SqlCommand comm = new SqlCommand())
                     {
                         comm.Connection = conn;
                         conn.Open();
                         string strTempGroupID = "TempGroup_" + DateTime.Now.ToString("yyyyMMddHHmmss");//定義臨時推播訊息群組ID
                         string strSQL = "INSERT INTO PushMessage_TempGroup (cMsgGroupID, cMsgGroupName, cMsgGroupPsw, cUserID) VALUES ('" + strTempGroupID + "','" + tbGroupName.Text + "','" + tbGroupPsw.Text + "','demoUser01')";
                         comm.CommandText = strSQL;
                         comm.ExecuteNonQuery();
                         //將人員加入PushMessage_TempGroupMember資料表
                         strSQL = "INSERT INTO PushMessage_TempGroupMember (cMsgGroupID, cUserID) VALUES ('" + strTempGroupID + "','demoUser01')";
                         //HintsDB.ExecuteNonQuery(strSQL);
                         comm.CommandText = strSQL;
                         comm.ExecuteNonQuery();
                         //儲存完後回到訊息模式選擇頁面
                         Page.RegisterClientScriptBlock("WindowOpen", "<script>window.open('../PushMessage/MessageModeChoose.aspx','MessageModeChoose', 'width=450, height=320, scrollbars=yes');window.close();</script>");
                     }
                 }
             }catch { }
         }
         else
             Page.RegisterClientScriptBlock("alert", "<script>alert('兩次輸入的密碼不同,請重新輸入密碼')</script>");
     else
         Page.RegisterClientScriptBlock("alert", "<script>alert('請輸入群組名稱')</script>");
 }
开发者ID:YC00,项目名称:jsplumb-with-signalr,代码行数:36,代码来源:CreateTempMsgGroup.aspx.cs

示例14: ImageButton1_Click

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            MessageBox.Show("Account succesfully Registered!",
              "Account Confirmation");
            string Email, UserId;
            Email = TextBox3.Text;
            UserId = TextBox7.Text;
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NORTHWNDConnectionString"].ConnectionString);
            string valCmd = "select UserId,Email from UDetail";
            SqlCommand CMD = new SqlCommand(valCmd, con);
            con.Open();
            string cmd = "insert into UDetail values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox7.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox3.Text + "') ";

            SqlCommand Cmd = new SqlCommand(cmd, con);

            Cmd.ExecuteNonQuery();
            Cmd.CommandText = "insert into login values('" + TextBox7.Text + "','" + TextBox4.Text + "','user')";

            Cmd.ExecuteNonQuery();
            Response.Cookies["UserId"].Value = TextBox7.Text;
            Response.Cookies["Pwd"].Value = TextBox4.Text;
            //Response.Cookies["role"].Value = "user";
            FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, true);
            con.Close();
            Response.Redirect("Login.aspx");

        }
    }
开发者ID:kjeans,项目名称:online-shop,代码行数:30,代码来源:Register.aspx.cs

示例15: anularPedidoBar

        public static bool anularPedidoBar(fPrincipal2 fPrincipal, Dictionary<int, int> pedido, int nroHab)
        {
            try
            {
                SqlCommand comm;
                comm = new SqlCommand("articulos_anularPedido", fPrincipal2.conn);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue("@nroHab", nroHab);

                foreach (int nroArt in pedido.Keys)
                {
                    comm.Parameters.AddWithValue("@nroArt", nroArt);
                    comm.Parameters.AddWithValue("@cant", pedido[nroArt]);
                    comm.ExecuteNonQuery();
                    // Anular registración en la tabla articulosConsumidos
                    comm.CommandText = "articulosConsumidos_quitar";
                    comm.ExecuteNonQuery();
                    //-----------------------------------------
                    comm.Parameters.RemoveAt("@nroArt");
                    comm.Parameters.RemoveAt("@cant");
                    comm.CommandText = "articulos_anularPedido";
                }

                tools.actualizarListadoTurnos(fPrincipal.dataGridView1, fPrincipal.dataGridView2);

                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:eljavidelomas,项目名称:HotelApp,代码行数:32,代码来源:Articulo.cs


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