SqlDataSource insert command ignored

  • Thread starter Thread starter Clodoaldo
  • Start date Start date
C

Clodoaldo

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
 
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 said:
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
 
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 said:
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:SqlDataSource ID="SqlDS_FV_trecho" runat="server"
ConnectionString="<%$ ConnectionStrings:Savi_desenConnectionString %>"
        InsertCommandType="Text"
        InsertCommand="x"
        OnInserted="SqlDS_FV_trecho_OnItemInserted"

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
 
Back
Top