Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Friday, March 9, 2012

How to read just inserted auto incremented primary key to use it as parameter?

Hi. After inserting data (new row) by using DetailsView control, how to read auto incremented primary key (identity) of this new row from sql database to use it as parameter passed to stored procedure?

Or in other way. I need to insert new row (let's call them parent row) in one table by using DetailsView control. This is quite easy. But after inserting I need to read primary key of this new row to insert new child row in other table. Both tables are in relation. How to do this? Any suggestions? Pawel.

Hi Pawelek,

Since the ID (primary key) is configured as an auto incremented field, the last row inserted will always have the maximum number.

You could write a stored procedure which selects the maximum ID number ( SELECT max(ID) from ParentRowsTable ) and returns it.
Then in your code you can execute the SP after you insert a row and you get the max. ID of the parent rows.

Greets,

Wim

|||Hi. I'm afraid that this is a risky business. What if in the same time some other people will insert new row which becomes row with maximum number? Is it possible such situation? Regards. Pawel.|||

Hi. you can return the@.@.IDENTITY

INSERT INTO [dbo].[table] (name, phone)VALUES ("test", "tttt")Return@.@.IDENTITY
|||I would recommend using SCOPE_IDENTITY() instead of @.@.IDENTITY. The former maintains the scope. Check out BOL for more info.

Wednesday, March 7, 2012

how to read an xml file on local file system

Hi,
i have a xml file c:\abcd.xml in my local filesystem.. i just want to
take the path as in parameter for a stored procedure and insert the values
into a table type variable
execute usp_xx (@.xmlpath='c:\abcd.xml')
-- inside the sp i would like to read the xml file and insert the same
into a table type variable..
Can anyone tell me the idea..
nsr
Message posted via http://www.webservertalk.comYou should read the file on the mid-tier/client and send the data as a
stored proc parameter value in SQL Server 2000. SQL Server 2005 will have a
way to read from files...
Best regards
Michael
"narasimha rao chandramouli via webservertalk.com"
<forum@.nospam.webservertalk.com> wrote in message
news:7a34860ffbc045ddaad40506b15e2a1b@.SQ
webservertalk.com...
> Hi,
> i have a xml file c:\abcd.xml in my local filesystem.. i just want to
> take the path as in parameter for a stored procedure and insert the values
> into a table type variable
> execute usp_xx (@.xmlpath='c:\abcd.xml')
> -- inside the sp i would like to read the xml file and insert the same
> into a table type variable..
> Can anyone tell me the idea..
>
> nsr
> --
> Message posted via http://www.webservertalk.com

how to read an xml file on local file system

Hi,
i have a xml file c:\abcd.xml in my local filesystem.. i just want to
take the path as in parameter for a stored procedure and insert the values
into a table type variable
execute usp_xx (@.xmlpath='c:\abcd.xml')
-- inside the sp i would like to read the xml file and insert the same
into a table type variable..
Can anyone tell me the idea..
nsr
Message posted via http://www.droptable.com
You should read the file on the mid-tier/client and send the data as a
stored proc parameter value in SQL Server 2000. SQL Server 2005 will have a
way to read from files...
Best regards
Michael
"narasimha rao chandramouli via droptable.com"
<forum@.nospam.droptable.com> wrote in message
news:7a34860ffbc045ddaad40506b15e2a1b@.droptable.co m...
> Hi,
> i have a xml file c:\abcd.xml in my local filesystem.. i just want to
> take the path as in parameter for a stored procedure and insert the values
> into a table type variable
> execute usp_xx (@.xmlpath='c:\abcd.xml')
> -- inside the sp i would like to read the xml file and insert the same
> into a table type variable..
> Can anyone tell me the idea..
>
> nsr
> --
> Message posted via http://www.droptable.com