小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

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

 牛人的尾巴 2016-03-09

很抱歉啊大家,之前上傳的代碼不是很詳細,現(xiàn)在我把這一段的代碼全部放上來
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ù)選擇的食物搜索出食物名字,食物價格
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+"'";//找出這個訂單的價格
                SqlCommand cmd1 = new SqlCommand(sqlstring, conn);
                SqlDataReader readPrice = cmd1.ExecuteReader();
                //
                readPrice.Read();
                decimal OrderPrice=Convert.ToDecimal(readPrice[0].ToString());
                readPrice.Close();
                //
                OrderPrice = OrderPrice + FoodPrice;//將訂單價格更新
                sqlstring = "select max(RelationId) as RelationIdMax from RelationTab";//找出關系表中關系ID最大項
                SqlCommand cmd2 = new SqlCommand(sqlstring, conn);
                SqlDataReader readrelationIdMax = cmd2.ExecuteReader();
                //
                readrelationIdMax.Read();
                int RelationIdMax = Convert.ToInt32(readrelationIdMax[0].ToString());
                RelationIdMax = ++RelationIdMax;//自加確保關系ID唯一
                readrelationIdMax.Close();
                //;
                string sqlUpdataString = "insert into table_RelationTab(RelationId,FoodId,OrderId,FoodName,FoodPrice) values(" + RelationIdMax + "," + FoodId + "," + OrderId + ",'" + FoodName + "'," + FoodPrice + ")";//更新關系表
                SqlCommand cmd3 = new SqlCommand(sqlUpdataString, conn);
                cmd3.CommandText = sqlUpdataString;
                sqlUpdataString = "update OrderTab set OrderPrice="+OrderPrice+" where OrderId="+OrderId+"";//更新訂單總價
                SqlCommand cmd4 = new SqlCommand(sqlUpdataString, conn);
                cmd4.CommandText = sqlUpdataString;
                sqlstring = "select RelationId,FoodName,FoodPrice from RelationTab where OrderId=" + OrderId + "";//找出關系表中更新后的菜譜,用于刷新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();//更新價格顯示
                //↑
                conn.Close();
            }
        }

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多