I wrote a procedure as follows
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)
Then I use the procedure as an Insert Query for ASPX Gridview (DEV Express)
Also I have a similar procedure for insert.
But in both cases all values I enter are being passed as Null and I get an Error "Cannot insert Null for Column CC_ID", and by using SQL Server Pofiler I found out that all values are being sent to SQL server as 'null'. Please help I have tried all that I know.
Thank you in advance.
<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>