乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C#中SQLserver語(yǔ)句insert語(yǔ)句無(wú)法更新數(shù)據(jù)

       牛人的尾巴 2016-03-09

      很抱歉啊大家,之前上傳的代碼不是很詳細(xì),現(xiàn)在我把這一段的代碼全部放上來(lái)
      private void OrderFoodAddButton_Click(object sender, EventArgs e)
      {
      if (IndentOderID != null)
      {
      using (SqlConnection conn = new SqlConnection(connectiongString))
      {
      conn.Open();
      //↓
      string sqlstring, FoodName;
      int FoodId = Convert.ToInt32(comboBox1.SelectedValue);
      decimal FoodPrice;
      Int64 OrderId = Convert.ToInt64(IndentOderID.Text.ToString());
      sqlstring = "select FoodName,FoodPrice from FoodTab where FoodId=" + FoodId + "";//根據(jù)選擇的食物搜索出食物名字,食物價(jià)格
      SqlCommand cmd = new SqlCommand(sqlstring, conn);
      SqlDataReader readfood = cmd.ExecuteReader();
      //
      readfood.Read();
      FoodName = readfood[0].ToString();
      FoodPrice = Convert.ToDecimal(readfood[1].ToString());
      readfood.Close();
      //

                      sqlstring="select OrderPrice from OrderTab where OrderId='"+OrderId+"'";//找出這個(gè)訂單的價(jià)格
                      SqlCommand cmd1 = new SqlCommand(sqlstring, conn);
                      SqlDataReader readPrice = cmd1.ExecuteReader();
                      //
                      readPrice.Read();
                      decimal OrderPrice=Convert.ToDecimal(readPrice[0].ToString());
                      readPrice.Close();
                      //
                      OrderPrice = OrderPrice + FoodPrice;//將訂單價(jià)格更新
                      sqlstring = "select max(RelationId) as RelationIdMax from RelationTab";//找出關(guān)系表中關(guān)系ID最大項(xiàng)
                      SqlCommand cmd2 = new SqlCommand(sqlstring, conn);
                      SqlDataReader readrelationIdMax = cmd2.ExecuteReader();
                      //
                      readrelationIdMax.Read();
                      int RelationIdMax = Convert.ToInt32(readrelationIdMax[0].ToString());
                      RelationIdMax = ++RelationIdMax;//自加確保關(guān)系ID唯一
                      readrelationIdMax.Close();
                      //;
                      string sqlUpdataString = "insert into table_RelationTab(RelationId,FoodId,OrderId,FoodName,FoodPrice) values(" + RelationIdMax + "," + FoodId + "," + OrderId + ",'" + FoodName + "'," + FoodPrice + ")";//更新關(guān)系表
                      SqlCommand cmd3 = new SqlCommand(sqlUpdataString, conn);
                      cmd3.CommandText = sqlUpdataString;
                      sqlUpdataString = "update OrderTab set OrderPrice="+OrderPrice+" where OrderId="+OrderId+"";//更新訂單總價(jià)
                      SqlCommand cmd4 = new SqlCommand(sqlUpdataString, conn);
                      cmd4.CommandText = sqlUpdataString;
                      sqlstring = "select RelationId,FoodName,FoodPrice from RelationTab where OrderId=" + OrderId + "";//找出關(guān)系表中更新后的菜譜,用于刷新GridView控件
                      SqlCommand cmd5 = new SqlCommand(sqlstring, conn);
                      cmd5.CommandText = sqlstring;
                      SqlDataAdapter adpfood = new SqlDataAdapter(sqlstring, conn);
                      DataSet dsfood = new DataSet();
                      adpfood.Fill(dsfood);
                      IndentBindingSource.DataSource = dsfood.Tables[0].DefaultView;
                      IndentGridView.DataSource = IndentBindingSource;
                      //
                      IndentOrderPrice.Text = OrderPrice.ToString();//更新價(jià)格顯示
                      //↑
                      conn.Close();
                  }
              }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多