Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

does not contain a definition for and no extension method

I am trying to get a variable from an Insert statement and pass it on as a querystring to another page.  I found some code behind but it does not like the Command syntax in "string Inc_ID = e.Command.Parameters["@Inc_ID"].Value.ToString();"

See attached code.

Thanks,
Brian
0
bchadez
Asked:
bchadez
  • 3
  • 2
3 Solutions
 
jorge_torizResearch & Development ManagerCommented:
Response.Redirect("YourNewPage.aspx?var=" + Server.UrlEncode(e.Command.Parameters["@Inc"].Value));
0
 
bchadezAuthor Commented:
Still doesn't like the word "Command" in the syntax?
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        Response.Redirect("Incident.aspx?var=" + Server.UrlEncode(e.Command.Parameters["@Inc"].Value));
    }
}

Open in new window

Capture.JPG
0
 
jorge_torizResearch & Development ManagerCommented:
aaaa, you are using the "insertED", there is no command there.

You must find the control that contains the information that you need to pass as a querystring variable, for example:

"YourPage.aspx?c=" + Server.UrlEncode(((HtmlGenericControl)detailsView1.FindControl("ControlId")).InnerText)
0
 
bchadezAuthor Commented:
So I'm still not sure how to get a variable from an Insert statement and pass it on as a querystring to another page?
Attached is my insert.
<asp:SqlDataSource ID="IncidentType_SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:GJPD_RIOConnectionString %>" 
            DeleteCommand="DELETE FROM [Incident] WHERE [Inc_ID] = @Inc_ID" 
            InsertCommand="INSERT INTO [Incident] ([Inc_Type]) VALUES (@Inc_Type);
SET @Inc_ID = SCOPE_IDENTITY();" 
            SelectCommand="SELECT [Inc_ID], [Inc_Type] FROM [Incident]" 
            
            UpdateCommand="UPDATE [Incident] SET [Inc_Type] = @Inc_Type WHERE [Inc_ID] = @Inc_ID">
            <DeleteParameters>
                <asp:Parameter Name="Inc_ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Inc_Type" Type="String" />
                <asp:Parameter Name="Inc_ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Inc_Type" Type="String" />
                <asp:Parameter Name="Inc_ID" />
            </InsertParameters>
        </asp:SqlDataSource>

Open in new window

0
 
jorge_torizResearch & Development ManagerCommented:
Mmm... check this code to read an identity value from a stored procedure.

The pAddTestStored procedure insert a new row in table with an identity column, then returns the new assigned value to the "Id" output parameter.

You must create a stored procedure where you return the identity value.
protected void Page_Load(object sender, EventArgs e)
{
    sdsTest.Insert();
}
protected void sdsTest_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
    Response.Output.Write(((SqlCommand)e.Command).Parameters["@Id"].Value.ToString());
}

<asp:SqlDataSource ID="sdsTest" runat="server" ConnectionString='<%$ connectionStrings:AW %>'
    InsertCommand="pAddTest" InsertCommandType="StoredProcedure" OnInserted="sdsTest_Inserted">
    <InsertParameters>
        <asp:Parameter Name="Val" DefaultValue="Test" Type="String" Size="10" />
        <asp:Parameter Name="Id" Direction="Output" Type="Int32" Size="4" />
    </InsertParameters>
</asp:SqlDataSource>

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now