locked
SQL server RRS feed

  • Question

  • how to input values into database and collect the new id to store in html?
    • Moved by Bob Beauchemin Thursday, May 22, 2014 1:11 AM Moved to the TSQL forum, not a SQLCLR issue
    Tuesday, May 20, 2014 8:19 AM

Answers

  • When a user inputs values into "navn" and "kommentar" on my webpage. I will save these into two values. The "navn" value shall be saved into the database table "bruker" where "bruker_id" is auto increment. Then I want to get back which bruker_id the "navn" was saved under.
    • Marked as answer by bandile Myeni Tuesday, May 20, 2014 2:34 PM
    Tuesday, May 20, 2014 9:26 AM
  • You can use SCOPE_IDENTITY() to return the assigned identity value back to the application:

    INSERT INTO dbo.bruker (navn, kommentar)
    	VALUES(@navn, @kommentar);
    SELECT SCOPE_IDENTITY() AS bruker_id;
    

    Another method is to return the value with an OUTPUT clause:

    INSERT INTO dbo.bruker (navn, kommentar)
    	OUTPUT inserted.bruker_id
    	VALUES(@navn, @kommentar);


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    • Marked as answer by bandile Myeni Tuesday, May 20, 2014 2:34 PM
    Tuesday, May 20, 2014 12:31 PM

All replies

  • Run SqlCommand against Sql server.

    Read Sql Command


    Many Thanks & Best Regards, Hua Min


    Tuesday, May 20, 2014 8:21 AM
  • Please checkout this resource for complete script to input values into database : http://html.net/tutorials/php/lesson19.php

    Carlo

    Tuesday, May 20, 2014 9:10 AM
  • When a user inputs values into "navn" and "kommentar" on my webpage. I will save these into two values. The "navn" value shall be saved into the database table "bruker" where "bruker_id" is auto increment. Then I want to get back which bruker_id the "navn" was saved under.
    • Marked as answer by bandile Myeni Tuesday, May 20, 2014 2:34 PM
    Tuesday, May 20, 2014 9:26 AM
  • You can use SCOPE_IDENTITY() to return the assigned identity value back to the application:

    INSERT INTO dbo.bruker (navn, kommentar)
    	VALUES(@navn, @kommentar);
    SELECT SCOPE_IDENTITY() AS bruker_id;
    

    Another method is to return the value with an OUTPUT clause:

    INSERT INTO dbo.bruker (navn, kommentar)
    	OUTPUT inserted.bruker_id
    	VALUES(@navn, @kommentar);


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    • Marked as answer by bandile Myeni Tuesday, May 20, 2014 2:34 PM
    Tuesday, May 20, 2014 12:31 PM