解決「將數據類型nvarchar轉換爲日期時間」錯誤後得到此解決方案。使用Vb.net/SQL Server 2000中通過一個gridview/SqlDataSource的更新一行:對象必須實現IConvertible?
存儲過程:
@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
任何想法?
我想你需要轉換爲SQL日期類型,它可能適用於更高版本的SQL服務器 – 2010-09-02 16:45:55
DateTime是2000年的一種類型,所以我不認爲這是問題? – Shawn 2010-09-02 16:52:22