I'm trying to pass a parameter in a SqlDataSource thru OnRowUpdating event in a Gridview control and i get...
Cannot insert the value NULL into column 'Address', table 'INFONET.dbo.ChecksAddress'; column does not allow nulls. INSERT fails.
The statement has been terminated.
My stored Procedure is
ALTER PROCEDURE [dbo].[sp_UpdateChecks]
@ID int,
@DID int,
@CashiersCheck bit,
@PayableTo varchar(MAX),
@Amount money,
@Purpose varchar(MAX),
@HasAddress bit,
@Address varchar(150),
@City varchar(150),
@State int,
@Zip varchar(50)
AS
BEGIN
SET NOCOUNT ON;
UPDATE Checks
SET CashiersCheck = @CashiersCheck,
PayableTo = @PayableTo,
Amount = @Amount,
Purpose = @Purpose
WHERE ID = @ID AND DID = @DID;
DELETE FROM ChecksAddress WHERE ID = @ID;
IF @HasAddress = 'True'
INSERT INTO ChecksAddress(Address, City, State, Zip, ID) VALUES(@Address, @City, @State, @Zip, @ID);
END
protected void uxChecksGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridView g = (GridView)sender;
RadioButtonList r = (RadioButtonList)g.Rows[e.RowIndex].FindControl("uxAddAddressRadioButtonList");
uxChecksSqlDataSource.UpdateParameters["HasAddress"].DefaultValue = r.SelectedValue;
if (Convert.ToBoolean(r.SelectedValue))
{
TextBox a = (TextBox)g.Rows[e.RowIndex].FindControl("uxCheckAddressTextBox");
TextBox c = (TextBox)g.Rows[e.RowIndex].FindControl("uxCheckCityTextBox");
DropDownList s = (DropDownList)g.Rows[e.RowIndex].FindControl("uxCheckStateDropDownList");
TextBox z = (TextBox)g.Rows[e.RowIndex].FindControl("uxCheckZipTextBox");
uxChecksSqlDataSource.UpdateParameters["Address"].DefaultValue = a.Text;
uxChecksSqlDataSource.UpdateParameters["City"].DefaultValue = c.Text;
uxChecksSqlDataSource.UpdateParameters["State"].DefaultValue = s.SelectedValue;
uxChecksSqlDataSource.UpdateParameters["Zip"].DefaultValue = z.Text;
}
}
aspx
<asp:SqlDataSource ID="uxChecksSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:db %>"
SelectCommandType="StoredProcedure"
SelectCommand="sp_GetChecksInformation"
DeleteCommandType="StoredProcedure"
DeleteCommand="sp_DeleteChecks"
InsertCommandType="StoredProcedure"
InsertCommand="sp_InsertChecks"
UpdateCommandType="StoredProcedure"
UpdateCommand="sp_UpdateChecks">
<SelectParameters>
<asp:SessionParameter Name="DID" SessionField="DID" />
</SelectParameters>
<DeleteParameters>
<asp:SessionParameter Name="DID" SessionField="DID" />
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="DID" />
<asp:Parameter Name="CashiersCheck" />
<asp:Parameter Name="PayableTo" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="Purpose" />
<asp:Parameter Name="HasAddress" />
<asp:Parameter Name="Address" />
<asp:Parameter Name="City" />
<asp:Parameter Name="State" />
<asp:Parameter Name="Zip" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CashiersCheck" />
<asp:Parameter Name="PayableTo" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="Purpose" />
<asp:Parameter Name="Address" />
<asp:Parameter Name="City" />
<asp:Parameter Name="State" />
<asp:Parameter Name="Zip" />
<asp:Parameter Name="HasAddress" />
<asp:SessionParameter Name="DID" SessionField="DID" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
Select allOpen in new window
by: angus_young_acdcPosted on 2009-03-10 at 14:16:43ID: 23851512
Have you stepped through your code to see if you actually pass the address value? You could always set the column/stored procedure to accept null values, which should stop that error.