首页 新闻 搜索 专区 学院

这段代码什么意思,怎样CSqlParameters对该类的一个对象赋值

0
悬赏园豆:5 [待解决问题]

[Serializable]
    public class CSqlParameters : ISerializable
    {
        private string m_strSqlText;
        private ArrayList m_arrayParams;

        public CSqlParameters()
        {
            m_strSqlText = "";
            m_arrayParams = new ArrayList();
        }

        public void Add(SqlParameter newParam)
        {
            m_arrayParams.Add(newParam);
        }

        public string SqlText
        {
            set { m_strSqlText = value; }
            get { return m_strSqlText; }
        }

        public ArrayList Parameters
        {
            get { return m_arrayParams; }
        }

        #region "For Serialize Support"
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("SqlText", m_strSqlText);
            info.AddValue("ParamCount", m_arrayParams.Count);
            for (int i = 0; i < m_arrayParams.Count; ++i)
            {
                info.AddValue("ParamName" + i.ToString(), ((SqlParameter)m_arrayParams[i]).ParameterName);
                info.AddValue("ParamSize" + i.ToString(), ((SqlParameter)m_arrayParams[i]).Size);
                info.AddValue("ParamValue" + i.ToString(), ((SqlParameter)m_arrayParams[i]).Value.ToString());
            }
        }

        protected CSqlParameters(SerializationInfo info, StreamingContext context)
        {
            m_arrayParams = new ArrayList();
            m_strSqlText = info.GetString("SqlText");
            int count = info.GetInt32("ParamCount");
            for (int i = 0; i < count; ++i)
            {
                string paramName = info.GetString("ParamName" + i.ToString());
                int paramSize = info.GetInt32("ParamSize" + i.ToString());
                object paramValue = info.GetString("ParamValue" + i.ToString());
                SqlParameter sqlParam = new SqlParameter(paramName, paramValue);
                sqlParam.Size = paramSize;
                m_arrayParams.Add(sqlParam);
            }
        }
        #endregion

    }

c#
杀  手的主页 杀 手 | 菜鸟二级 | 园豆:213
提问于:2012-07-10 11:50
< >
分享
所有回答(2)
0

看代码是处理SQL参数的

artwl | 园豆:16536 (专家六级) | 2012-07-10 11:58

谢谢

支持(0) 反对(0) 杀 手 | 园豆:213 (菜鸟二级) | 2012-07-10 17:54
0

应该是 一个 对 SqlParameter 进行序列化反序列化.

赋值:

CSqlParameters p = new CSqlParameters();

p.SqlText = "select * from aspnet_Memberships where UserName=@UserName";

p.Add(new SqlParameter("@UsrName", "admin");

序列化调用的是:GetObjectData(SerializationInfo info, StreamingContext context)

反序列化会调用:protected CSqlParameters(SerializationInfo info, StreamingContext context)

 

怎么序列化和反序列,可以看下ISerializable用法

 

元夕 | 园豆:202 (菜鸟二级) | 2012-07-10 12:59

谢谢

支持(0) 反对(0) 杀 手 | 园豆:213 (菜鸟二级) | 2012-07-10 17:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册