Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Strore procedure using xml...help!!!

Author  Topic 

bluestar
Posting Yak Master

133 Posts

Posted - 2008-10-02 : 11:29:54
I have a store procedure to insert multiple data from the datagrid which has 2 columns.


ALTER PROCEDURE [dbo].[sp_InsertCounterStyle]
(
@TOCHSCounterStyleID int,
@xmlList XML
)


AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Begin tran

Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText)

Select
@TOCHSCounterStyleID,
path.xl.value('@TOCHSCounterNumber','int') as TOCHSCounterNumber,
path.xl.value('@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelText

from @xmlList.nodes('/xmlList') as path(xl)

--commit tran

END

when I am executing this ...
I am entering data in 2 places

@TOCHSCounterStyleID int :::: 11
@xmlList ::::<xmlList><TOCHSCounterNumber=1>/TOCHSCounterNumber>TOCHSCounterLabelText=''i''></TOCHSCounterLabelText></xmlList>


then its giving me error
Msg 9455, Level 16, State 1, Procedure sp_InsertCounterStyle, Line 0
XML parsing: line 1, character 29, illegal qualified name character


please help


Thank You

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-02 : 12:05:03
quote:
Originally posted by bluestar

I have a store procedure to insert multiple data from the datagrid which has 2 columns.


ALTER PROCEDURE [dbo].[sp_InsertCounterStyle]
(
@TOCHSCounterStyleID int,
@xmlList XML
)


AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Begin tran

Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText)

Select
@TOCHSCounterStyleID,
path.xl.value('@TOCHSCounterNumber','int') as TOCHSCounterNumber,
path.xl.value('@TOCHSCounterLabelText','varchar(20)') as TOCHSCounterLabelText

from @xmlList.nodes('/xmlList') as path(xl)

--commit tran

END

when I am executing this ...
I am entering data in 2 places

@TOCHSCounterStyleID int :::: 11
@xmlList ::::<xmlList><TOCHSCounterNumber=1></TOCHSCounterNumber><TOCHSCounterLabelText=''i''></TOCHSCounterLabelText></xmlList>


then its giving me error
Msg 9455, Level 16, State 1, Procedure sp_InsertCounterStyle, Line 0
XML parsing: line 1, character 29, illegal qualified name character


please help


Thank You


your xml is not correct. modify as above
Go to Top of Page

bluestar
Posting Yak Master

133 Posts

Posted - 2008-10-02 : 12:13:45
thanks for the reply,

Actually there was error while copy pasting,

this what I did....
<xmlList><TOCHSCounterNumber=1></TOCHSCounterNumber><TOCHSCounterLabelText=''i''></TOCHSCounterLabelText></xmlList>


but still its giving me error....

Is there something wrong with SP???

will this one statement
from @xmlList.nodes('/xmlList') as path(xl)

is okay for both the 2 variables.????

I mean do I have to write something

from @xmlList.nodes('/xmlList') as path(xl,xl)


please help

Thank You





Go to Top of Page

bluestar
Posting Yak Master

133 Posts

Posted - 2008-10-02 : 12:57:34
is my store procedure wrong or something else ...

please help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 02:14:06
quote:
Originally posted by bluestar

is my store procedure wrong or something else ...

please help


i think its the probelm with xml value passed pass something like this

'<xmlList><TOCHSCounterNumber value="1"></TOCHSCounterNumber><TOCHSCounterLabelText value="i"></TOCHSCounterLabelText></xmlList>'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 03:16:11
[code]ALTER PROCEDURE [dbo].[sp_InsertCounterStyle]
(
@TOCHSCounterStyleID int,
@xmlList XML
)


AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Begin tran

Insert into TOCHSCounterStyle(TOCHSCounterStyleID,TOCHSCounterNumber,TOCHSCounterLabelText)

Select
@TOCHSCounterStyleID,
x.c.value('(./TOCHSCounterNumber/@value)[1]','int'),
x.c.value('(./TOCHSCounterLabelText/@value)[1]','varchar(10)')
from @x.nodes('/list/xmlList') x(c)
--commit tran

END[/code]

and call like this

[code]EXEC [dbo].[sp_InsertCounterStyle] IDvalue,'<list><xmlList><TOCHSCounterNumber value="1"></TOCHSCounterNumber><TOCHSCounterLabelText value="i"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="12123"></TOCHSCounterNumber><TOCHSCounterLabelText value="ifqewferf"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="9986"></TOCHSCounterNumber><TOCHSCounterLabelText value="wqrwertetggrti"></TOCHSCounterLabelText></xmlList></list>'[/code]

also dont use sp_ for spnames as it will cause it first search among systems sps.
Go to Top of Page

bluestar
Posting Yak Master

133 Posts

Posted - 2008-10-03 : 11:39:30
okay 1st of all thanks for reply.
I am getting an error when I am executing the SP
Msg 8152, Level 16, State 14, Procedure sp_InsertCounterStyle, Line 20
String or binary data would be truncated.
The statement has been terminated.

(1 row(s) affected)


Please do reply

Thnak You
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-03 : 11:43:38
quote:
Originally posted by bluestar

okay 1st of all thanks for reply.
I am getting an error when I am executing the SP
Msg 8152, Level 16, State 14, Procedure sp_InsertCounterStyle, Line 20
String or binary data would be truncated.
The statement has been terminated.

(1 row(s) affected)


Please do reply

Thnak You


check if the character fields TOCHSCounterNumber,TOCHSCounterLabelText have enough length to hold the values extracted from xml.The error suggests the value coming from xml is bigger than the fields' current size and its getting truncated.
Go to Top of Page

bluestar
Posting Yak Master

133 Posts

Posted - 2008-10-07 : 10:07:42
hello visakh16

please help me in this,
your stored procedure is working fine,but I want the input xml string in this form
<xmlList>
<xl>1</xl>
<xl>i</xl>
<xl>2</xl>
<xl>ii</xl>
<xl>3</xl>
<xl>iii</xl>
</xmlList>

this is because in my C# code this xml string is generated,but my SP is excepting this string


<xmlList><TOCHSCounterNumber value="1"></TOCHSCounterNumber><TOCHSCounterLabelText value="i"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="12123"></TOCHSCounterNumber><TOCHSCounterLabelText value="ifqewferf"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="9986"></TOCHSCounterNumber><TOCHSCounterLabelText value="wqrwertetggrti"></TOCHSCounterLabelText></xmlList>

please help me

this is my C# code

protected void btnsubmit_Click(object sender, EventArgs e) {

int schemaid;

schemaid = tocheaderstyle.InsertTOCNumberingSchema(txtname.Text);

String xmlList = GetList();

tocheaderstyle.InsertTOCCounterStyle(schemaid,xmlList);



}
private String GetList() {
XmlDocument doc = new XmlDocument();
XmlElement elem = doc.CreateElement("xmlList");
doc.AppendChild(elem);

XmlElement root = doc.DocumentElement;
for (int i = 0; i < dgItem.Rows.Count; i++)
{
XmlElement infoEle = doc.CreateElement("xl");
XmlElement infoEle1 = doc.CreateElement("xl");

DataRowView drv = (DataRowView)dgItem.Rows[i].DataItem;
TextBox tb = (TextBox)dgItem.Rows[i].FindControl("txtdrgno");
TextBox tb1 = (TextBox)dgItem.Rows[i].FindControl("txtdrgno1");
if((tb.Text != "") && (tb1.Text != ""))
{
//infoEle.SetAttribute("TOCHSCounterNumber", TOCHSCounterNumber);
infoEle.InnerText = tb.Text;
root.AppendChild(infoEle);
//infoEle.SetAttribute("TOCHSCounterLabelText", TOCHSCounterLabelText);
infoEle1.InnerText = tb1.Text;
root.AppendChild(infoEle1);
//infoEle.InnerText = tb.Text;
//infoEle1.InnerText = tb1.Text;
}
}
string s = doc.InnerXml;
return s;
}

please do reply

thank you

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-07 : 10:18:06
quote:
Originally posted by bluestar

hello visakh16

please help me in this,
your stored procedure is working fine,but I want the input xml string in this form
<xmlList>
<xl>1</xl>
<xl>i</xl>
<xl>2</xl>
<xl>ii</xl>
<xl>3</xl>
<xl>iii</xl>
</xmlList>

this is because in my C# code this xml string is generated,but my SP is excepting this string


<xmlList><TOCHSCounterNumber value="1"></TOCHSCounterNumber><TOCHSCounterLabelText value="i"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="12123"></TOCHSCounterNumber><TOCHSCounterLabelText value="ifqewferf"></TOCHSCounterLabelText></xmlList><xmlList><TOCHSCounterNumber value="9986"></TOCHSCounterNumber><TOCHSCounterLabelText value="wqrwertetggrti"></TOCHSCounterLabelText></xmlList>

please help me

this is my C# code

protected void btnsubmit_Click(object sender, EventArgs e) {

int schemaid;

schemaid = tocheaderstyle.InsertTOCNumberingSchema(txtname.Text);

String xmlList = GetList();

tocheaderstyle.InsertTOCCounterStyle(schemaid,xmlList);



}
private String GetList() {
XmlDocument doc = new XmlDocument();
XmlElement elem = doc.CreateElement("xmlList");
doc.AppendChild(elem);

XmlElement root = doc.DocumentElement;
for (int i = 0; i < dgItem.Rows.Count; i++)
{
XmlElement infoEle = doc.CreateElement("xl");
XmlElement infoEle1 = doc.CreateElement("xl");

DataRowView drv = (DataRowView)dgItem.Rows[i].DataItem;
TextBox tb = (TextBox)dgItem.Rows[i].FindControl("txtdrgno");
TextBox tb1 = (TextBox)dgItem.Rows[i].FindControl("txtdrgno1");
if((tb.Text != "") && (tb1.Text != ""))
{
//infoEle.SetAttribute("TOCHSCounterNumber", TOCHSCounterNumber);
infoEle.InnerText = tb.Text;
root.AppendChild(infoEle);
//infoEle.SetAttribute("TOCHSCounterLabelText", TOCHSCounterLabelText);
infoEle1.InnerText = tb1.Text;
root.AppendChild(infoEle1);
//infoEle.InnerText = tb.Text;
//infoEle1.InnerText = tb1.Text;
}
}
string s = doc.InnerXml;
return s;
}

please do reply

thank you




post this in some dot net forums. i'm not a dot net developer. Anything related to sql post here.
Go to Top of Page
   

- Advertisement -