我写了一个程序如下
USE [Farm_Project]
GO
/****** Object: StoredProcedure [dbo].[prod1_insert] Script Date: 11/12/2014 1:21:20 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[prod1_insert]
(
@coop_id int,
@good_eggs int=0,
@broken_eggs int=0,
@small_eggs int= 0,
@date smalldatetime=null
)
AS
if @date is null
set @date=getdate()
insert into Prod1 (cc_id, gd_Eggs, br_Eggs, sm_Eggs, Prod_date )
values
(@coop_id ,@good_eggs, @broken_eggs, @small_eggs,@date)
然后我将该过程用作ASPX Gridview的插入查询(DEV Express)
我也有类似的插入程序。
但是在这两种情况下,我输入的所有值都被传递为Null并且我得到一个错误"无法为列CC_ID"插入Null,并且通过使用SQL Server Pofiler我发现所有值都被发送到SQL服务器为' null'。请帮助我尝试了所有我知道的事情。
提前谢谢。
<dx:GridViewCommandColumn ShowDeleteButton="True" ShowEditButton="True" ShowNewButtonInHeader="True" VisibleIndex="0">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="prod_ID" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="cc_id" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="gd_Eggs" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="br_Eggs" VisibleIndex="4">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="sm_Eggs" VisibleIndex="5">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Total" ReadOnly="True" VisibleIndex="6">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Trays" ReadOnly="True" VisibleIndex="7">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Eggs_xtra" ReadOnly="True" VisibleIndex="8">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataDateColumn FieldName="Prod_date" VisibleIndex="9">
</dx:GridViewDataDateColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource ID="prodSource" runat="server" ConnectionString="<%$ ConnectionStrings:Farm_ProjectConnectionString %>" DeleteCommand="prod1_delete"
InsertCommand="prod1_insert"
SelectCommand="prod1_select"
UpdateCommand="prod1_update"
DeleteCommandType="StoredProcedure"
InsertCommandType="StoredProcedure"
OnInserted="prodSource_Inserted"
SelectCommandType="StoredProcedure"
UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="prod_id" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="coop_id" Type="Int32" />
<asp:Parameter Name="good_eggs" Type="Int32" />
<asp:Parameter Name="broken_eggs" Type="Int32" />
<asp:Parameter Name="small_eggs" Type="Int32" />
<asp:Parameter Name="date" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="prod_ID" />
<asp:Parameter Name="code" Type="Int32" />
<asp:Parameter Name="good_eggs" Type="Int32" />
<asp:Parameter Name="broken_eggs" Type="Int32" />
<asp:Parameter Name="small_eggs" Type="Int32" />
<asp:Parameter Name="date" Type="DateTime" />
</UpdateParameters>