SqlDataSource insert command ignored

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
 
M

Milosz Skalecki [MCAD]

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
 
C

Clodoaldo

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top