SqlDataSource insert command ignored

Discussion in 'ASP .Net' started by Clodoaldo, Jul 25, 2008.

  1. Clodoaldo

    Clodoaldo Guest

    The insert command in the sqlDataSource is ignored. The OnInserted
    event is executed.

    As the command was ignored i issued a wrong insert command ("x") just
    to see if it would throw an execption but it didn't.

    <asp:FormView ID="FV_trecho" runat="server"
    DataSourceID="SqlDS_FV_trecho" >

    <InsertItemTemplate>
    ....
    <asp:LinkButton ID="LinkButton_Inserir" runat="server" Text="Inserir"
    CommandName="Insert" ></asp:LinkButton>
    ....
    </InsertItemTemplate>

    </asp:FormView>

    <asp:SqlDataSource ID="SqlDS_FV_trecho" runat="server"
    ConnectionString="<%$ ConnectionStrings:Savi_desenConnectionString %>"
    InsertCommandType="Text"
    InsertCommand="x"
    OnInserted="SqlDS_FV_trecho_OnItemInserted"
    >

    <InsertParameters>
    ....
    </InsertParameters>

    It executes the OnInserted event redirecting to another page:

    protected void SqlDS_FV_trecho_OnItemInserted(object sender,
    SqlDataSourceStatusEventArgs e)
    {
    string viagem_id =
    e.Command.Parameters["@viagem_id"].Value.ToString();
    Response.Redirect("~/trechos.aspx?viagem_id=" + viagem_id);
    }


    Any ideas?

    Regards, Clodoaldo Pinto Neto
     
    Clodoaldo, Jul 25, 2008
    #1
    1. Advertising

  2. Hi,

    Form view control allows to handle exceptions in the Inserted/Deleted/Edited
    events, by exposing few properties in the SqlDataSourceStatusEventArgs class.
    Calling Redirect in one of the listed event handlers, ends current execution
    so the e.ExceptionHandled flag is not used to rethrow the exception (put a
    breakpoint in the ItemInserted event handler and inspect e.Exception to see
    exactly) . In order to see the default exception handling mechanism, which
    obviously is standard ASP.NET error page add if (e.Exception == null) to your
    event handler:

    protected void SqlDS_FV_trecho_OnItemInserted(object sender,
    SqlDataSourceStatusEventArgs e)
    {
    if (e.Exception == null)
    {
    string viagem_id = e.Command.Parameters["@viagem_id"].Value.ToString();
    Response.Redirect("~/trechos.aspx?viagem_id=" + viagem_id);
    }
    }

    HTH
    --
    Milosz


    "Clodoaldo" wrote:

    > The insert command in the sqlDataSource is ignored. The OnInserted
    > event is executed.
    >
    > As the command was ignored i issued a wrong insert command ("x") just
    > to see if it would throw an execption but it didn't.
    >
    > <asp:FormView ID="FV_trecho" runat="server"
    > DataSourceID="SqlDS_FV_trecho" >
    >
    > <InsertItemTemplate>
    > ....
    > <asp:LinkButton ID="LinkButton_Inserir" runat="server" Text="Inserir"
    > CommandName="Insert" ></asp:LinkButton>
    > ....
    > </InsertItemTemplate>
    >
    > </asp:FormView>
    >
    > <asp:SqlDataSource ID="SqlDS_FV_trecho" runat="server"
    > ConnectionString="<%$ ConnectionStrings:Savi_desenConnectionString %>"
    > InsertCommandType="Text"
    > InsertCommand="x"
    > OnInserted="SqlDS_FV_trecho_OnItemInserted"
    > >

    > <InsertParameters>
    > ....
    > </InsertParameters>
    >
    > It executes the OnInserted event redirecting to another page:
    >
    > protected void SqlDS_FV_trecho_OnItemInserted(object sender,
    > SqlDataSourceStatusEventArgs e)
    > {
    > string viagem_id =
    > e.Command.Parameters["@viagem_id"].Value.ToString();
    > Response.Redirect("~/trechos.aspx?viagem_id=" + viagem_id);
    > }
    >
    >
    > Any ideas?
    >
    > Regards, Clodoaldo Pinto Neto
    >
     
    Milosz Skalecki [MCAD], Jul 25, 2008
    #2
    1. Advertising

  3. Clodoaldo

    Clodoaldo Guest

    On 25 jul, 14:16, Milosz Skalecki [MCAD] <>
    wrote:
    > Hi,
    >
    > Form view control allows to handle exceptions in the Inserted/Deleted/Edited
    > events, by exposing few properties in the SqlDataSourceStatusEventArgs class.
    > Calling Redirect in one of the listed event handlers, ends current execution
    > so the e.ExceptionHandled flag is not used to rethrow the exception (put a
    > breakpoint in the ItemInserted event handler and inspect e.Exception to see
    > exactly) . In order to see the default exception handling mechanism, which
    > obviously is standard ASP.NET error page add if (e.Exception == null) to your
    > event handler:
    >
    > protected void SqlDS_FV_trecho_OnItemInserted(object sender,
    > SqlDataSourceStatusEventArgs e)
    > {
    >         if (e.Exception == null)
    >         {
    >                 string viagem_id = e.Command.Parameters["@viagem_id"].Value.ToString();
    >                         Response.Redirect("~/trechos.aspx?viagem_id=" + viagem_id);
    >         }
    >
    > }
    >
    > HTH


    Yes, not only that helps but indeed solves it.

    Thank You, Clodoaldo.

    > --
    > Milosz
    >
    > "Clodoaldo" wrote:
    > > The insert command in the sqlDataSource is ignored. The OnInserted
    > > event is executed.

    >
    > > As the command was ignored i issued a wrong insert command ("x") just
    > > to see if it would throw an execption but it didn't.

    >
    > > <asp:FormView ID="FV_trecho" runat="server"
    > > DataSourceID="SqlDS_FV_trecho" >

    >
    > > <InsertItemTemplate>
    > > ....
    > > <asp:LinkButton ID="LinkButton_Inserir" runat="server" Text="Inserir"
    > >     CommandName="Insert" ></asp:LinkButton>
    > > ....
    > > </InsertItemTemplate>

    >
    > > </asp:FormView>

    >
    > > <asp:SqlDataSource ID="SqlDS_FV_trecho" runat="server"
    > > ConnectionString="<%$ ConnectionStrings:Savi_desenConnectionString %>"
    > >         InsertCommandType="Text"
    > >         InsertCommand="x"
    > >         OnInserted="SqlDS_FV_trecho_OnItemInserted"

    >
    > > <InsertParameters>
    > > ....
    > > </InsertParameters>

    >
    > > It executes the OnInserted event redirecting to another page:

    >
    > >     protected void SqlDS_FV_trecho_OnItemInserted(object sender,
    > > SqlDataSourceStatusEventArgs e)
    > >     {
    > >         string viagem_id =
    > > e.Command.Parameters["@viagem_id"].Value.ToString();
    > >         Response.Redirect("~/trechos.aspx?viagem_id=" + viagem_id);
    > >     }

    >
    > > Any ideas?

    >
    > > Regards, Clodoaldo Pinto Neto
     
    Clodoaldo, Jul 25, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hrvoje Vrbanc

    SqlDataSource INSERT query and TextBox text

    Hrvoje Vrbanc, Dec 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    4,417
    Hrvoje Vrbanc
    Dec 8, 2005
  2. =?Utf-8?B?RGFiYmxlcg==?=

    insert row using Gridview and SqlDataSource?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    10,715
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 20, 2006
  3. Replies:
    7
    Views:
    6,516
    Vlad Iliescu
    Apr 20, 2006
  4. mosscliffe
    Replies:
    3
    Views:
    9,573
    mosscliffe
    Apr 28, 2006
  5. Jason
    Replies:
    2
    Views:
    1,050
    Jason
    Nov 12, 2006
Loading...

Share This Page