本帖最后由 hxfjsw 于 2010-08-12 19:36:03 编辑

解决方案 »

  1.   

    没有提供相关参数@SmallImage
    贴出objectDateSource看看
      

  2.   

    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;
                        }
                    }
                }
            }
      

  3.   

    没有大侠在listView中使用fileUpload上传的吗?
    大侠你是用的什么方法呢?