当前位置:编程学习 > C#/ASP.NET >>

无法转换

protected void Button1_Click(object sender, EventArgs e)
    {
        string shop_id=Session["shop_id"];
        string oldcard,newcard,reason,description;
        int ret;
        if (this.txtoldcard.ToString() == ""||this.txtnewcard.ToString()=="")
        {
            return;
        }
        oldcard = this.txtoldcard.ToString();
        newcard = this.txtnewcard.ToString();
        reason = "000"+this.DropDownList1.SelectedIndex.ToString();
        description = this.TextBox1.ToString();
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        string param = "proc1";
        conn.Open();
        SqlCommand cmd = new SqlCommand(param, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter paramshop_id = new SqlParameter("@shop_id", SqlDbType.VarChar);
        SqlParameter paramoldcard = new SqlParameter("@oldcard ", SqlDbType.VarChar);
        SqlParameter paramnewcard = new SqlParameter("@newcard ", SqlDbType.VarChar);
        SqlParameter paramreason = new SqlParameter("@reason", SqlDbType.VarChar);
        SqlParameter paramdescription = new SqlParameter("@description", SqlDbType.VarChar);
        SqlParameter paramret = new SqlParameter("@ret", SqlDbType.VarChar, 4);
       // SqlParameter parammorderid = new SqlParameter("@orderid", SqlDbType.VarChar, 500);
        try
        {
            paramshop_id.Value = shop_id;
            paramoldcard.Value = oldcard;
            paramnewcard.Value = newcard;
            paramreason.Value = reason;
            paramdescription.Value = description;
            //paramret.Value = lInfo;

            paramret.Direction = ParameterDirection.Output;
            //parammorderid.Direction = ParameterDirection.Output;

            cmd.Parameters.Add(paramshop_id);
            cmd.Parameters.Add(paramoldcard);
            cmd.Parameters.Add(paramnewcard);
            cmd.Parameters.Add(paramreason);
            cmd.Parameters.Add(paramdescription);
            cmd.Parameters.Add(paramret);



            cmd.ExecuteNonQuery();
        }
        catch (Exception e1)
        {
        }
}
运行时报的错误是错误无法将类型“object”隐式转换为“string”。存在一个显式转换(是否缺少强制转换?)

麻烦各位大侠帮忙看一下是什么原因,谢谢。 --------------------编程问答--------------------

  if (this.txtoldcard.ToString() == ""||this.txtnewcard.ToString()=="")
        {
            return;
        }
oldcard = this.txtoldcard.ToString();
        newcard = this.txtnewcard.ToString();


 this.txtoldcard.Text;
       this.txtnewcard.Text;
--------------------编程问答-------------------- 是文本 Text,不是对象 --------------------编程问答-------------------- string shop_id=Session["shop_id"]==null?"":Session["shop_id"].toString();
--------------------编程问答-------------------- description = this.TextBox1.ToString();
=>
description = this.TextBox1.Text;
--------------------编程问答--------------------

if (Session["shop_id"] != null)
{
shop_id=Session["shop_id"].ToString();
}
--------------------编程问答-------------------- this.TextBox1.Text.ToString()

 this.txtoldcard.Text.ToString()
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,