我取出表里边的值转换成string赋值到label.text,我现在要反过来,不知道怎么做?

解决方案 »

  1.   

    /// <param name="sender"></param>
    /// <param name="e"></param>
    private bool btn_CCExchg_Save_Click()
    {
    try
    {
    ComLogOutput.WriteLogFile("btn_CCExchg_Save_Click Begin");

    bool flag = true;
    //Creat a new datatable
    DataTable dtUpt = null;

    if(this.Session["dsp_TripReport_CCExchg"]==null)
    {
    BindData_pnlCCExchg();
    } //Copy the construct of the dataset
    DataTable dtOri = (DataTable)this.Session["dsp_TripReport_CCExchg"];
    dtUpt= dtOri.Copy(); for(int intDs = 0; intDs < dg_CCExchg.Items.Count;intDs++)
    {
    string CurrSell = ((UC_Curr)dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_CurrSell")).GetSelectValue;
    TextBox AmtSell = ((TextBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_txt_AmtSell"));
    UC_Curr CurrBuy = ((UC_Curr)dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_CurrBuy"));
    TextBox AmtBuy = ((TextBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_txt_AmtBuy"));
    TextBox RatioAB = ((TextBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_txt_RatioAB"));
    TextBox RatioHKD = ((TextBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_txt_RatioHKD"));
    string CompanyRate = ((CheckBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_chk_CompanyRate")).Checked?"T":"F";
    TextBox Receipt = ((TextBox)this.dg_CCExchg.Items[intDs].FindControl("dg_CCExchg_txt_Receipt")); if(ComStyleCheck.CheckRequired(AmtSell.Text.Trim()) && !ComStyleCheck.CheckMoneyValue(AmtSell.Text.Trim(),6,2))
    {
    AmtSell.BackColor = Color.Red;
    flag=false;
    }
    else
    {
    AmtSell.BackColor = Color.White; if(AmtSell.Text.Trim() !="")
    {
    dtUpt.Rows[intDs]["AMT_SELL"] =  AmtSell.Text.Trim();
    }
    } if(ComStyleCheck.CheckRequired(AmtBuy.Text.Trim()) && !ComStyleCheck.CheckMoneyValue(AmtBuy.Text.Trim(),6,2))
    {
    AmtBuy.BackColor = Color.Red;
    flag=false;
    }
    else
    {
    AmtBuy.BackColor = Color.White; if(AmtBuy.Text.Trim() !="")
    {
    dtUpt.Rows[intDs]["AMT_BUY"] =  AmtBuy.Text.Trim();
    }
    } if(ComStyleCheck.CheckRequired(RatioAB.Text.Trim()) && !ComStyleCheck.CheckMoneyValue(RatioAB.Text.Trim(),2,4))
    {
    RatioAB.BackColor = Color.Red;
    flag=false;
    }
    else
    {
    RatioAB.BackColor = Color.FromArgb(217,217,217); if(RatioAB.Text.Trim() !="")
    {
    dtUpt.Rows[intDs]["RATIO"] =  RatioAB.Text.Trim();
    }
    } if(ComStyleCheck.CheckRequired(RatioHKD.Text.Trim()) && !ComStyleCheck.CheckMoneyValue(RatioHKD.Text.Trim(),2,4))
    {
    RatioHKD.BackColor = Color.Red;
    flag=false;
    }
    else
    {
    RatioHKD.BackColor = Color.FromArgb(217,217,217); if(RatioHKD.Text.Trim() !="")
    {
    dtUpt.Rows[intDs]["RATIO_BASE"] =  RatioHKD.Text.Trim();
    }
    }

    if(Receipt.Text.Trim().Replace("-","").Length > 5)
    {
    Receipt.BackColor = Color.Red;
    flag = false;
    }
    else
    {
    Receipt.BackColor = Color.White;
    dtUpt.Rows[intDs]["ATTACHMENT"] =  Receipt.Text.Trim().Replace("-","");
    }
      
    dtUpt.Rows[intDs]["CURR_SELL"] =  CurrSell.Trim(); dtUpt.Rows[intDs]["CURR_BUY"] =  CurrBuy.GetSelectValue.Trim(); dtUpt.Rows[intDs]["COMP_RATE"] =  CompanyRate;
    }

    if(flag == false)
    {
    //lbl_Err.Text = "you must input correct info !";
    lbl_Err.Text = ComLocalDiff.GetMessageById("1126",UserInfo.LangCode); return false;
    }
    // update DB
    new TripReportDB().UpdateCCExchg(gs_cmpy.Value,is_serial.Value,UserInfo.UID,dtUpt); new TripReportDB().UpdateRe(gs_cmpy.Value,is_serial.Value,UserInfo.UID,"3",txt_CCExchg_Re.Text); BindData_pnlCCExchg(); ComLogOutput.WriteLogFile("btn_CCExchg_Save_Click end");

    return true;
    }
    catch(Exception ex)
    {
    ComLogOutput.WriteLogFile(ex);

    lbl_Err.Text = ex.Message; return false;
    }
    }
      

  2.   

    string a;
    string update;
    string source="server=192.168.1.3;"+"uid=sa;pwd=sa;"+"database=northwind";
    string select="SELECT 公司名称 from wy where 标记=0 order by newid()";
    SqlConnection conn=new SqlConnection(source);
    conn.Open();
    SqlCommand cmd=new SqlCommand(select,conn);
    SqlDataReader areader=cmd.ExecuteReader();
    if(areader.Read())//这句是一定要的
    {
    label1.Text = areader["公司名称"].ToString();
    }
    areader.Close();
                a=label1.Text;
    update="update wy set 标记=1 where 公司名称=a";
    SqlCommand up=new SqlCommand(update,conn);
    up.ExecuteNonQuery();
    运行程序,报错,a变量有问题,请大家看看怎么修改?
      

  3.   

    int i;
    i = int.Parse(label.text);