对象必须实现IConvertible?

时间:2010-09-02 16:41:29

标签: sql stored-procedures sqldatasource iconvertible

解决“将数据类型nvarchar转换为datetime”错误后获取此错误。使用Vb.net/SQL Server 2000通过gridview / sqldatasource更新行:

存储过程:

@ISTag varchar(10),
@PCISTag varchar(10),
@User varchar(50),
@Date_Start datetime,
@Date_End datetime,
@Status varchar(50),
@Cost money,
@Notes varchar(500),
@CreatedBy varchar(50),
@ModifiedBy varchar(50)
AS
BEGIN
    SET NOCOUNT ON;

    EXEC sp_changeLog 'HardDrive', @ISTag, @ModifiedBy

    UPDATE T_HardDrive
            SET PCIStag = @PCISTag,
            [User] = @User,
            Date_Start = @Date_Start,
            Date_End = @Date_End,
            [Status] = @Status,
            Cost = @Cost,
            Notes = @Notes,
            ModifiedBy = @ModifiedBy
        WHERE ISTag = @ISTag

SQL数据源:

<asp:SqlDataSource ID="InventoryHardDrive" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>" 
                        DeleteCommand="DELETE FROM [T_HardDrive] WHERE [ISTag] = @original_ISTag" 
                        InsertCommand="sp_HardDriveInsert" InsertCommandType="StoredProcedure" 
                        OldValuesParameterFormatString="original_{0}" 
                        SelectCommand="sp_HardDriveSelect" SelectCommandType="StoredProcedure" 
                        UpdateCommand="sp_HardDriveUpdate" UpdateCommandType="StoredProcedure">
                        <DeleteParameters>

                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="ISTag" Type="String" />
                            <asp:Parameter Name="PCISTag" Type="String" />
                            <asp:Parameter Name="User" Type="String" />
                            <asp:Parameter Name="Date_Start" Type="DateTime" />
                            <asp:Parameter Name="Date_End" Type="DateTime" />
                            <asp:Parameter Name="Status" Type="String" />
                            <asp:Parameter Name="Cost" Type="Decimal" />
                            <asp:Parameter Name="Notes" Type="String" />
                            <asp:Parameter Name="CreatedBy" Type="String" />
                            <asp:Parameter Name="ModifiedBy" Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:ControlParameter ControlID="hideInactiveCheckBox" Name="Active" 
                                PropertyName="Checked" Type="Boolean" />
                            <asp:ControlParameter ControlID="filterText" DefaultValue="%" Name="ISTag" 
                                PropertyName="Text" Type="String" />
                        </SelectParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="ISTag" Type="String" />
                            <asp:Parameter Name="PCISTag" Type="String" />
                            <asp:Parameter Name="User" Type="String" />
                            <asp:Parameter Name="Date_Start" Type="DateTime" />
                            <asp:Parameter Name="Date_End" Type="DateTime" />
                            <asp:Parameter Name="Status" Type="String" />
                            <asp:Parameter Name="Cost" Type="Decimal" />
                            <asp:Parameter Name="Notes" Type="String" />
                            <asp:Parameter Name="CreatedBy" Type="String" />
                            <asp:Parameter Name="ModifiedBy" Type="String" />
                        </UpdateParameters>
                    </asp:SqlDataSource>

我现在将Date_Start和Date_End参数设置为最小日期,直到我能够找出导致此问题的原因。

Dim sqldatenull As SqlDateTime
sqldatenull = SqlDateTime.MinValue
e.NewValues("Date_Start") = sqldatenull
e.NewValues("Date_End") = sqldatenull

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您是否尝试在VB.NET代码中使用DateTime而不是SqlDateTime