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

菜鸟求教 无法上传图片

--------------------编程问答-------------------- 没有提供相关参数@SmallImage
贴出objectDateSource看看
--------------------编程问答-------------------- objectDateSource

    <asp:ObjectDataSource ID="dataSource" runat="server" 
        DataObjectTypeName="chinaredstar.Models.Purchase"  TypeName="chinaredstar.Models.Purchase"
        InsertMethod="Insert" SelectMethod="SelectEmpty">
    </asp:ObjectDataSource>

model

        public Purchase()
        {
            this.CreateTime = System.DateTime.Now;
        }

        /// <summary>
        /// ID
        /// </summary>
        [Column]
        public Guid ID
        {
            get;
            set;
        }

        /// <summary>
        ///  团购标题
        /// </summary>
        [Column]
        public string Title
        {
            get;
            set;
        }

        /// <summary>
        /// 链接
        /// </summary>
        [Column]
        public string Url
        {
            get;
            set;
        }

        /// <summary>
        /// 内容
        /// </summary>
        [Column]
        public string Content
        {
            get;
            set;
        }

        /// <summary>
        /// 浏览量
        /// </summary>
        [Column]
        public int PageViews
        {
            get;
            set;
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Column]
        public DateTime CreateTime
        {
            get;
            set;
        }

        /// <summary>
        /// 状态
        /// </summary>
        [Column]
        public bool State
        {
            get;
            set;
        }


        /// <summary>
        /// 小图
        /// </summary>
        [Column]
        public String SmallImage
        {
            get;
            set;
        }
    }


entity 的 insert方法

        public virtual bool Insert()
        {
            if (this.ID is Guid)
            {
                this.ID = (I)Convert.ChangeType(Guid.NewGuid(), typeof(I));
            }

            Type type = this.GetType();
            List<PropertyInfo> ps = new List<PropertyInfo>(type.GetProperties().Where<PropertyInfo>(p => p.Name != "ID" && p.GetCustomAttributes(typeof(ColumnAttribute), true).Length > 0));

            using (SqlConnection connection = ConnectionHelper.CreateConnection())
            {
                SqlCommand command = connection.CreateCommand();
                if (this.ID is Guid)
                {
                    command.CommandText = String.Format(
                        "INSERT INTO {0}({1}) VALUES({2})",
                        (type.GetCustomAttributes(typeof(TableAttribute), true)[0] as TableAttribute).TableName,
                        ps.Aggregate<PropertyInfo, string>("ID", (s, p) => s + "," + p.Name),
                        ps.Aggregate<PropertyInfo, string>("@ID", (s, p) => s + ",@" + p.Name));

                    command.Parameters.AddWithValue("@ID", this.ID);
                }
                else // 认为 ID 是自增的。
                {
                    command.CommandText = String.Format(
                        "INSERT INTO {0}({1}) VALUES({2});SELECT @@IDENTITY;",
                        (type.GetCustomAttributes(typeof(TableAttribute), true)[0] as TableAttribute).TableName,
                        ps.Aggregate<PropertyInfo, string>("", (s, p) => s + "," + p.Name).Substring(1),
                        ps.Aggregate<PropertyInfo, string>("", (s, p) => s + ",@" + p.Name).Substring(1));
                }

                ps.ForEach(p =>
                {
                    command.Parameters.AddWithValue("@" + p.Name,
                        p.PropertyType.IsEnum ?
                        Convert.ChangeType(p.GetValue(this, null), Enum.GetUnderlyingType(p.PropertyType))
                        :
                        p.GetValue(this, null));
                });

                connection.Open();
                if (this.ID is Guid)
                {
                    return command.ExecuteNonQuery() > 0;
                }
                else
                {
                    object o = command.ExecuteScalar();
                    if (o is I)
                    {
                        this.ID = (I)Convert.ChangeType(o, typeof(I));
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }

--------------------编程问答-------------------- 没有大侠在listView中使用fileUpload上传的吗?


大侠你是用的什么方法呢?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,