Hello ,
I am stumped by this Error in ASP .NET when trying to insert a record thru DetailsView web control :
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Insert' that has parameters: ProductName, SupplierID, CategoryID, QuantityPerUnit, price, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued, UnitPrice.
below is my details view , the object data source its connected thru and the custom class that i wrote which simply calls down the table adapters insert method. The tabladapter's insert method works just fine when i try it from the designer but is always giving this error from the page :(. I m using Northwind db for this application, can anyone please tell me wats causing this error ?
Custom class ( for products table in Northwind db) :
[System.ComponentModel.
DataObject]public
class ProductsBRL{
public ProductsBRL(){
// // TODO: Add constructor logic here //}
[System.ComponentModel.
DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)] public int Insert(string productname,int? supplierid,int? categoryid,string quantityperunit,decimal? price,short? unitsinstock,short? unitsonorder,short? reorderlevel,bool discontinued){
NorthwindTableAdapters.
ProductsTableAdapter adpProducts = new ProductsTableAdapter(); int res = adpProducts.Insert(productname, supplierid, categoryid, quantityperunit, price, unitsinstock, unitsonorder, reorderlevel, discontinued); return res;}
[System.ComponentModel.
DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)] public Northwind.ProductsDataTable GetProducts(){
NorthwindTableAdapters.
ProductsTableAdapter adpProducts = new ProductsTableAdapter(); return adpProducts.GetProducts();}
}
<
asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" Height="50px" Width="125px" AllowPaging="True"> <Fields> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" /> <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" /> <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" /> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" /> <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" /> <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" /> <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" /> <asp:CommandField ShowInsertButton="True" /> Fields> asp:DetailsView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert" SelectMethod="GetProducts" TypeName="ProductsBRL"> <InsertParameters> <asp:Parameter Name="productname" Type="String" /> <asp:Parameter Name="supplierid" Type="Int32" /> <asp:Parameter Name="categoryid" Type="Int32" /> <asp:Parameter Name="quantityperunit" Type="String" /> <asp:Parameter Name="price" Type="Decimal" /> <asp:Parameter Name="unitsinstock" Type="Int16" /> <asp:Parameter Name="unitsonorder" Type="Int16" /> <asp:Parameter Name="reorderlevel" Type="Int16" /> <asp:Parameter Name="discontinued" Type="Boolean" /> InsertParameters> asp:ObjectDataSource>
Insert command text in tableadapter :
INSERT INTO Products
(ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued)
VALUES (@ProductName,@SupplierID,@CategoryID,@QuantityPerUnit,@UnitPrice,@UnitsInStock,@UnitsOnOrder,@ReorderLevel,@Discontinued)
Replies
Know the answer? Post it — somebody with the same question will find it here.