L
lcorrias
i try to do a simple insert using SQLDataSource and a Stored Procedure
I try all night and always have this error
Object Must Implement IConvertible
I can't understand where I wrong..
Looking around I understand is maybe a typecasting problema but I not
find nothing more understeable..
Could someone tell me why Microsoft release this SQLdatasorce making
more difficult a simple insert?
If someone could help me to fix this problem please
Here is the code
------------------------------------------------------------------------------------------------------------
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Try
SqlDataSource1.Insert()
Catch ex As Exception
Response.Write(ex.ToString)
Finally
SqlDataSource1.Dispose()
End Try
End Sub
------------------------------------------------------------------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
InsertCommandType="StoredProcedure"
InsertCommand="dbo.StoredProcedure1">
<InsertParameters>
<asp:ControlParameter ControlID="DropDownListCategory"
Name="@CategoryID" PropertyName="SelectedValue"
Type="Int32" />
<asp:ControlParameter ControlID="DropDownListCategory"
Name="@ModelNumber" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="txtModelName"
Name="@ModelName" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtProductImage"
Name="@ProductImage" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtUnitCost"
Name="@UnitCost" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="txtDescription"
Name="@Description" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtWeight"
Name="@Weight" PropertyName="Text" Type="Decimal" />
<asp:ControlParameter ControlID="txtDiscount"
Name="@Discount" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="chkIsActive"
Name="@isActive" PropertyName="Checked"
Type="Boolean" />
<asp:ControlParameter ControlID="DropDownListAuthors"
Name="@IDAuthor" PropertyName="SelectedItem"
Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE dbo.StoredProcedure1
@CategoryID int,
@ModelNumber nvarchar(50),
@ModelName nvarchar(50),
@ProductImage nvarchar(50),
@UnitCost money,
@Description varchar(500),
@weight money,
@IsActive bit,
@DiscountPerCent int,
@IDAuthor int
AS
INSERT INTO dbo.CMRC_Products (
CategoryID,
ModelNumber,
ModelName,
ProductImage,
UnitCost,
Description,
weight,
IsActive,
DiscountPerCent,
IDAuthor
)
VALUES (
@CategoryID,
@ModelNumber,
@ModelName,
@ProductImage,
@UnitCost,
@Description,
@weight,
@IsActive,
@DiscountPerCent,
@IDAuthor
)
SELECT @@IDENTITY as [NewID]
------------
I try all night and always have this error
Object Must Implement IConvertible
I can't understand where I wrong..
Looking around I understand is maybe a typecasting problema but I not
find nothing more understeable..
Could someone tell me why Microsoft release this SQLdatasorce making
more difficult a simple insert?
If someone could help me to fix this problem please
Here is the code
------------------------------------------------------------------------------------------------------------
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Try
SqlDataSource1.Insert()
Catch ex As Exception
Response.Write(ex.ToString)
Finally
SqlDataSource1.Dispose()
End Try
End Sub
------------------------------------------------------------------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CommerceTemplate %>"
InsertCommandType="StoredProcedure"
InsertCommand="dbo.StoredProcedure1">
<InsertParameters>
<asp:ControlParameter ControlID="DropDownListCategory"
Name="@CategoryID" PropertyName="SelectedValue"
Type="Int32" />
<asp:ControlParameter ControlID="DropDownListCategory"
Name="@ModelNumber" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="txtModelName"
Name="@ModelName" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtProductImage"
Name="@ProductImage" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtUnitCost"
Name="@UnitCost" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="txtDescription"
Name="@Description" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="txtWeight"
Name="@Weight" PropertyName="Text" Type="Decimal" />
<asp:ControlParameter ControlID="txtDiscount"
Name="@Discount" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="chkIsActive"
Name="@isActive" PropertyName="Checked"
Type="Boolean" />
<asp:ControlParameter ControlID="DropDownListAuthors"
Name="@IDAuthor" PropertyName="SelectedItem"
Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE dbo.StoredProcedure1
@CategoryID int,
@ModelNumber nvarchar(50),
@ModelName nvarchar(50),
@ProductImage nvarchar(50),
@UnitCost money,
@Description varchar(500),
@weight money,
@IsActive bit,
@DiscountPerCent int,
@IDAuthor int
AS
INSERT INTO dbo.CMRC_Products (
CategoryID,
ModelNumber,
ModelName,
ProductImage,
UnitCost,
Description,
weight,
IsActive,
DiscountPerCent,
IDAuthor
)
VALUES (
@CategoryID,
@ModelNumber,
@ModelName,
@ProductImage,
@UnitCost,
@Description,
@weight,
@IsActive,
@DiscountPerCent,
@IDAuthor
)
SELECT @@IDENTITY as [NewID]
------------