I have a strange problem...The code below showing the SqlDataSource, when i run this code, SelectCommand is work, and i pretty sure each GridView Column's DataField has bind the correct value, when i press the update button to UpdateCommand, if @attribute_value_id
is 0 ,do INSERT, else do UPDATE.
however, when it do the update is 100% work, but if insert, the 2 parameters : @zone_id and @attribute_value_id gone NULL,i make me mad, because , if it is really gone NULL before pass to Datasource, it can't be do the INSERT if @attribute_value_id is not
0. So any peoples help?
<asp:SqlDataSource ID="sdsCarrierFees" runat="server" ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:CorrectConnectionString %>"
SelectCommand="sp_GetCarrierFees"
SelectCommandType="StoredProcedure"
UpdateCommand="if @attribute_value_id = 0 begin insert into shipping_fees (zone_id, attribute_value_id) values (@zone_id, @attribute_value_id); end else begin update shipping_attribute_value set attribute_value=@zone_id where attribute_value_id=@attribute_value_id end;"
>
<SelectParameters>
<asp:ControlParameter Name="Para_Carrier_Id" ControlID="ddlCarrier" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="attribute_value_id" Type="Int32" />
<asp:Parameter Name="zone_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
My Blog : http://www.netatlantis.com
I am a Chinese and live in HongKong
Sorry for my poor English. m(._.")m
SilverNight
Member
582 Points
186 Posts
SQLDatasource cannot contain INSERT query?
Jul 16, 2010 03:04 PM|LINK
I have a strange problem...The code below showing the SqlDataSource, when i run this code, SelectCommand is work, and i pretty sure each GridView Column's DataField has bind the correct value, when i press the update button to UpdateCommand, if @attribute_value_id is 0 ,do INSERT, else do UPDATE.
however, when it do the update is 100% work, but if insert, the 2 parameters : @zone_id and @attribute_value_id gone NULL,i make me mad, because , if it is really gone NULL before pass to Datasource, it can't be do the INSERT if @attribute_value_id is not 0. So any peoples help?
<asp:SqlDataSource ID="sdsCarrierFees" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:CorrectConnectionString %>" SelectCommand="sp_GetCarrierFees" SelectCommandType="StoredProcedure" UpdateCommand="if @attribute_value_id = 0 begin insert into shipping_fees (zone_id, attribute_value_id) values (@zone_id, @attribute_value_id); end else begin update shipping_attribute_value set attribute_value=@zone_id where attribute_value_id=@attribute_value_id end;" > <SelectParameters> <asp:ControlParameter Name="Para_Carrier_Id" ControlID="ddlCarrier" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="attribute_value_id" Type="Int32" /> <asp:Parameter Name="zone_id" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource>I am a Chinese and live in HongKong
Sorry for my poor English. m(._.")m
SilverNight
Member
582 Points
186 Posts
Re: SQLDatasource cannot contain INSERT query?
Jul 16, 2010 06:46 PM|LINK
I fixed that, the DataField show not be set ReadOnly="true" ,because it render as <span> ,not <input>, it will not pass value when postback.
I am a Chinese and live in HongKong
Sorry for my poor English. m(._.")m