Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Imrankhan Pathan 14 posts 33 karma points
    Sep 05, 2012 @ 08:57
    Imrankhan Pathan
    0

    Get Identity value by SqlHelper.ExecuteNonQuery

    Hello friends.

    I have create custome module in umbraco, I am inserting product data into umbraco database, I want to get Identity value newly inserted product on Save button click event.

    My code is here.

    int rows = SqlHelper.ExecuteNonQuery(string.Format("insert into products(SubCategoryId,Name,ShortDescription) values({0},'{1}','{2}')",p.SubCategoryId, p.Name, p.ShortDescription));
                    if (rows > 0)
                    {
                        int id = SqlHelper.ExecuteScalar<int>("select @@IDENTITY");
                        return id;
                    }
                    return 0;

     

    Thanks

    Imrankhan

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Sep 06, 2012 @ 17:56
  • Imrankhan Pathan 14 posts 33 karma points
    Sep 08, 2012 @ 12:49
    Imrankhan Pathan
    0

    Actually I was talking about umbraco SqlHelper class.

    umbraco.BusinessLogic.Application.SqlHelper.ExecuteNonQuery("CommandText");

    Anyways, I got this solution by umbraco.BusinessLogic.Application.SqlHelper.ExecuteScalar<int>("Insert Statement; select @@IDENTITY;");

    Thanks

    Imrankhan

Please Sign in or register to post replies

Write your reply to:

Draft