新建一个User时候出错 求助大侠们
“/”应用程序中的服务器错误。--------------------------------------------------------------------------------
无法创建抽象类。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.MissingMethodException: 无法创建抽象类。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
添加页面:
程序代码:
<asp:ObjectDataSource runat ="server" ID="UserDetailSource" SelectMethod ="GetUserById" InsertMethod ="add" UpdateMethod="Update" TypeName =" YL.PinHong.BLL.admin" DataObjectTypeName ="YL.PinHong.BLL.admin" OnInserted="UserDetailSource_Inserted" > <SelectParameters > <asp:QueryStringParameter Name="Id" QueryStringField ="Id" Type ="int32" /> </SelectParameters> </asp:ObjectDataSource> <asp:ObjectDataSource ID="StateDataSource" runat ="server" TypeName ="YL.PinHong.BLL.States" SelectMethod ="getUserStates" /> <asp:ObjectDataSource ID="RoleDataSource" runat="server" TypeName ="YL.PinHong.BLL.Roles" SelectMethod="getRolesList" /> <asp:DetailsView ID="userdetails" runat ="server" AutoGenerateRows ="false" AutoGenerateInsertButton ="true" AutoGenerateEditButton ="true" DataSourceID ="UserDetailSource" DataKeyNames ="Id" > <Fields > <asp:TemplateField HeaderText="用户名"> <EditItemTemplate> <asp:TextBox ID="Name" Text=' <%# Bind("Name") %>' runat="server" /> <asp:RequiredFieldValidator ID="ValidateName" Display="Dynamic" ControlToValidate="Name" runat="server" ErrorMessage="请输入用户名"> </asp:RequiredFieldValidator> <asp:CustomValidator ID="ValidateExit" runat="server" ControlToValidate="Name" Display="Dynamic" ErrorMessage="此用户已存在" OnServerValidate="ValidateExit_ServerValidate"> </asp:CustomValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="密码"> <EditItemTemplate> <asp:TextBox ID="Password" TextMode="Password" Text=' <%# Bind("Password") %>' runat="server" /> <asp:RequiredFieldValidator ID="ValidatePassword" Display="Dynamic" runat="server" ErrorMessage="请输入密码" ControlToValidate="Password"> </asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="确认密码"> <EditItemTemplate> <asp:TextBox ID="ValPassword" TextMode="Password" runat="server" /> <asp:RequiredFieldValidator ID="ValidatePassword2" Display="Dynamic" runat="server" ErrorMessage="请输入确认密码" ControlToValidate="ValPassword"> </asp:RequiredFieldValidator> <asp:CompareValidator ID="ComparePassword" runat="server" Display="Dynamic" ControlToCompare="Password" ControlToValidate="ValPassword" ErrorMessage="两次密码输入不一致"> </asp:CompareValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText ="头像"> <EditItemTemplate > <asp:TextBox runat ="server" ID="Face" Text =' <%# Bind("Face") %>'/> <asp:FileUpload runat="server" ID="FulFile" /> <asp:Button ID ="ButtonUpload" runat ="server" Text ="上传" CausesValidation ="false" OnClick="ButtonUpload_Click" /> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="用户状态"> <EditItemTemplate> <asp:DropDownList ID="UserState" DataSourceID="StateDataSource" runat="server" SelectedValue=' <%# Bind("StateId") %>' DataTextField="Name" DataValueField="Id" AppendDataBoundItems="true"> <asp:ListItem Text="请选择状态" Value="" /> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="UserState" Display="Dynamic" runat="server" ErrorMessage="请选择状态"> </asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="用户角色"> <EditItemTemplate> <asp:DropDownList ID="UserRole" DataSourceID="RoleDataSource" runat="server" SelectedValue=' <%# Bind("RoleId") %>' DataTextField="Name" DataValueField="Id" AppendDataBoundItems="true"> <asp:ListItem Text="请选择角色" Value="" /> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="请选择状态" ControlToValidate="UserRole" Display="Dynamic"> </asp:RequiredFieldValidator> </EditItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView>
方法:
程序代码:
public static int add(Models.Admin user) { string sql = "insert into [Admin] ([Name],[Password],[Face],[StateId],[RoleId]) values (@name,@password,@face,@stateId,@roleId)"; SqlParameter[] parameters = {new SqlParameter ("@name",user.Name ), new SqlParameter ("@password",user.Password ), new SqlParameter ("@face",user.Face ), new SqlParameter ("@stateId",user .StateId ), new SqlParameter ("@roleId",user .RoleId )}; return DbHelperSql.ExecuteSql(sql, parameters); }