| Author |
Topic |
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 11:22:04
|
| Hello Here is my stored procedure,I want to insert multiple data from the datagrid to the database.This is the 1st time I am using xml in Stored procedure..so I need guidance in this.CREATE PROCEDURE dbo.sp_InsertCounterStyle ( @TOCHSCounterStyleID int, @xmlList XML)ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText) Select @TOCHSCounterStyleID, @xmlList.value('@TOCHSCounterNumber','int') as TOCHSCounterNumber, @xmlList.value('@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelText from @xmlList.nodes('/xmlList') as xmlList ENDGOI am getting following error.....The table (and its columns) returned by a table-valued method need to be aliased.Please help...thank You |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 11:26:21
|
try like thisCREATE PROCEDURE dbo.sp_InsertCounterStyle(@TOCHSCounterStyleID int,@xmlList XML)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText)Select @TOCHSCounterStyleID,xmlList.xl.value('@TOCHSCounterNumber','int') as TOCHSCounterNumber,xmlList.xl.value('@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelTextfrom @xmlList.nodes('/xmlList') as xmlList(xl) ENDGO |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 11:29:59
|
| then it saying Msg 227, Level 15, State 1, Procedure sp_InsertCounterStyle, Line 20"xl" is not a valid function, property, or field.BTW what is xl in this case????why do we need it???Thanks For reply |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 11:34:27
|
quote: Originally posted by bluestar then it saying Msg 227, Level 15, State 1, Procedure sp_InsertCounterStyle, Line 20"xl" is not a valid function, property, or field.BTW what is xl in this case????why do we need it???Thanks For reply
its column alias. b/w are you using sql 2005? |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 11:35:36
|
| yes I am using sql server 2005 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 11:53:37
|
Try like this:-CREATE PROCEDURE dbo.sp_InsertCounterStyle(@TOCHSCounterStyleID int,@xmlList XML)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText)Select @TOCHSCounterStyleID,xmlList.xl.value('./@TOCHSCounterNumber','int') as TOCHSCounterNumber,xmlList.xl.value('./@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelTextfrom @xmlList.nodes('/xmlList')xmlList(xl)ENDGO |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 11:57:45
|
| thanks for the reply.But its still saying the same thing"xl" is not a valid function, property, or field.please help!!!!Thank You. |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 12:01:16
|
| do I have to declare 'xl' somewhere else also ??? |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 12:51:05
|
| Okay Is there any other way I can write similar Stored procedure using xml???Mine one is not working,,,and I am not being able to understand the error........ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 12:52:28
|
quote: Originally posted by bluestar do I have to declare 'xl' somewhere else also ???
just try only this and see if it worksCREATE PROCEDURE dbo.sp_InsertCounterStyle(@TOCHSCounterStyleID int,@xmlList XML)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Select xmlList.xl.value('./@TOCHSCounterNumber','int') as TOCHSCounterNumber,xmlList.xl.value('./@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelTextfrom @xmlList.nodes('/xmlList')xmlList(xl)ENDGO |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 12:59:40
|
| I tried executing only thisCREATE PROCEDURE dbo.sp_InsertCounterStyle(@TOCHSCounterStyleID int,@xmlList XML)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Select xmlList.xl.value('./@TOCHSCounterNumber','int') as TOCHSCounterNumber,xmlList.xl.value('./@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelTextfrom @xmlList.nodes('/xmlList')xmlList(xl)ENDGOI am getting the same error...I hope I dont have to create any empty xml file for this. Because I am being told that from datagrid ,data will be stored in memory,then I have to write a function which will traverse thru grid and insert data in the table. In the function I have to pass xml file as string.Thanks for the help!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 13:06:26
|
quote: Originally posted by bluestar I tried executing only thisCREATE PROCEDURE dbo.sp_InsertCounterStyle(@TOCHSCounterStyleID int,@xmlList XML)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;Select path.xl.value('./@TOCHSCounterNumber','int') as TOCHSCounterNumber,path.xl.value('./@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelTextfrom @xmlList.nodes('/xmlList')path(xl)ENDGOI am getting the same error...I hope I dont have to create any empty xml file for this. Because I am being told that from datagrid ,data will be stored in memory,then I have to write a function which will traverse thru grid and insert data in the table. In the function I have to pass xml file as string.Thanks for the help!!!
i think its getting confised b/w two aliases. try changing alias as above.If still it doesnt work use OPENXML method.http://www.sqlservercentral.com/articles/OpenXML/usingopenxml/1881/ |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 13:20:00
|
| thanks the error is corrected.One last question,How can I execute this Stored procedure to check whether its working correctly or not.I am executing it then it is saying me to enter just 2 paramenters,the TOCHSCounterStyleID and xmlList,I want it to run by entering @TOCHSCounterNumber and TOCHSCounterLabelText, this is where the data will be added in GridView.Thanks Again |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 13:22:53
|
quote: Originally posted by bluestar thanks the error is corrected.One last question,How can I execute this Stored procedure to check whether its working correctly or not.I am executing it then it is saying me to enter just 2 paramenters,the TOCHSCounterStyleID and xmlList,I want it to run by entering @TOCHSCounterNumber and TOCHSCounterLabelText, this is where the data will be added in GridView.Thanks Again
Then you should add @TOCHSCounterNumber and TOCHSCounterLabelText also as parameters to stored procedure and change code to use their values also inside. |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 13:27:52
|
| but if I add them in stored procedure as declare @TOCHSCounterLabelText and @TOCHSCounterNumber, then there will be no use of xml.I am using xml because thoese two columns have multiple data to be inserted.Please do reply to this,I want to clear my doutThank You |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 13:30:28
|
quote: Originally posted by bluestar but if I add them in stored procedure as declare @TOCHSCounterLabelText and @TOCHSCounterNumber, then there will be no use of xml.I am using xml because thoese two columns have multiple data to be inserted.Please do reply to this,I want to clear my doutThank You
dont you get the values of above fields from xml? then why do you want variables? |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 13:34:50
|
| so in that case,I have to create an xml file with those two values and pass to stored procedure ...right???? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-23 : 13:42:45
|
quote: Originally posted by bluestar so in that case,I have to create an xml file with those two values and pass to stored procedure ...right????
yup. that should be it.that helps you to insert the multiple row values into db together. |
 |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-23 : 13:44:22
|
| okay thanks a ton!!! |
 |
|
|
|