Respondida Purpose of using -1 as a record number

  • martes, 24 de abril de 2012 15:06
     
     

    Hi,

    I'm working an example out of textbook, and it is using a method that has an optional parameter with a default value of -1as a record number to refresh a detailsview control. 

    This is probably a stupid question, but what is the purpose of using this technique.

    Also, after an insert, how would I retrieve the primary key of the record just added.

    Thanx in advance,

    Tom


    Thomas G Magaro


    • Editado Tom Magaro martes, 24 de abril de 2012 15:07 Left out information
    •  

Todas las respuestas

  • miércoles, 25 de abril de 2012 15:16
     
     

    I haven't seen your book so I can only guess. My guess is that the -1 is used to return 0 records into the form, resulting in an empty form. If that is the purpose, that sounds like the hard way to do it.

    If you don't know the primary key of the row that you entered, I going to guess that the table has an identify column. You might be able to use the IDENT_CURRENT function. See http://msdn.microsoft.com/en-us/library/ms175098.aspx


    Rick Byham, Microsoft, SQL Server Books Online, Implies no warranty

  • miércoles, 25 de abril de 2012 19:52
    Moderador
     
     

    Hello,

    It could be useful to provide the title of the book and maybe the code of your method.

    I prefer to use SCOPE_IDENTITY than IDENT_CURRENT because i always put my INSERT ( inside a stored procedure )   between a BEGIN TRANSACTION and the commit and i load the value of SCOPE_IDENTITY in an OUTPUT parameter of the stored procedure to "keep" its value. But it is a question of taste ( and habit ) , not to critisize Rick as i know his replies are always good or at least very useful.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • jueves, 26 de abril de 2012 0:44
     
     

    Thanks Rick for the info.  I'll look into it.

    As for the book I'm working out of, it is call Web Development using Visual Studio 2005.

    Tom


    Thomas G Magaro

  • viernes, 27 de abril de 2012 11:30
    Moderador
     
     Respondida

    Hello,

    SQL Server 2005 is ending its lifetime. It would be more useful to study SQL Server 2008/2008 R2 or SQL Server 2012.

    Moreover, if you are are SQL Server Express 2005, you might have problems when you will try an upgrade towards 2008/2008 R/2012 ( problem coming partly from SSMSEE which provokes the failure of the upgrade ). If you are using your own computer , uninstall the whole SQL Server Express 2005 and install a "full" edition 2008 R2 or 2012 ( SQL Server Express with advanced services will permit the install of SSMSE , the Reporting Services and the full-text ...).

    Don't hesitate to post again for more help or explanations.

    Have a nice day

    PS : the full name of the edition and version would be useful


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    • Marcado como respuesta KJian_ martes, 01 de mayo de 2012 5:08
    •