我在编程中想给SqlCommand增加属性Parameters,也就是下面的语句,但是调试结果说:Add()方法没有value属性。
CmdObj.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).value= txtDescription.Text;
希望大家能帮助小弟一下。

解决方案 »

  1.   

    你是要传递一个参数吧?
    用CmdObj.Parameters.AddWithValue()方法要比CmdObj.Parameters.Add()方法方便的多,建议这样用!CmdObj.Parameters.Add()里面有两个参数,第一个是参数名字,第二个是要传递的值Value。
      

  2.   


                    SqlParameter[] arrParm = new SqlParameter[]
                    {
                        new SqlParameter("@intReturn",SqlDbType.Int,4,ParameterDirection.ReturnValue,false,0,0,string.Empty,DataRowVersion.Default,null),
                        new SqlParameter("@id",id),
                        new SqlParameter("@password",password),
                        new SqlParameter("@name",name),
                        new SqlParameter("@borntime",borntime),
                        new SqlParameter("@sex",sex),
                        new SqlParameter("@item",item),
                        new SqlParameter("@tel",tel),
                        new SqlParameter("@mobile",mobile),
                        new SqlParameter("@email",email),
                        new SqlParameter("@qq",qq),
                        new SqlParameter("@address",address),
                        new SqlParameter("@youbian",youbian),
                        new SqlParameter("@memo",memo),
                        new SqlParameter("@action",action)
                    };
                    sm.ExecNonSP("mem_manage", arrParm);
                    int intreturn = Convert.ToInt32(arrParm[0].Value);
                    sm.Close();
                    return intreturn;
                }
      

  3.   

    CmdObj.Parameters.Add( "@ImageDescription ",   SqlDbType.VarChar,   200);
    CmdObj.Parameters["ImageDescription "].value=txtDescription.Text;
      

  4.   

    Value  大写呀! 小写value肯定是没有的哦..!
      

  5.   

    [code=C#]SqlCommand UpdateCmd = new SqlCommand(UpdateStr,Con);
            SqlParameter ParmID = new SqlParameter("@ID", SqlDbType.NVarChar,20);
            ParmID.Value = ID;
      

  6.   

    CmdObj.Parameters.Add( "@ImageDescription ",   SqlDbType.VarChar,   200);
    CmdObj.Parameters["ImageDescription "].value=txtDescription.Text;
    正确 写法!
      

  7.   

    第一次见到有象楼主这样加的, 如果要象你那样加的话, 也应该是这样:CmdObj.Parameters.Add( "@ImageDescription ",   txtDescription.Text);  // 你就不要管数据类型了, 你添加的数据类型与DB的一样就行了.
      

  8.   

    不好意思,是我自己粗心给写错了
    我没有注意“value”的大小写问题
    应该是“Value”开头字母要大写
    谢谢大家了!
    大家也给我提供了好的方法。