unable to insert multiple listbox items in to database

Posted on 2008-09-30
Last Modified: 2012-05-05

here insertcommand is stored procedure,selected list is list box,packagemaster is column name

when i try to insert multiple list items in to pakagemaster column using items property  it was not suggest me  to handle this situation
Question by:life_j
  • 2
LVL 14

Accepted Solution

Binuth earned 500 total points
Comment Utility
which version of DB you using ?
LVL 14

Expert Comment

Comment Utility
pass as xml parameter to Sp and use sp_xml_preparedocument sp to insert xml values to Tabel
(see sample code)
C# code building Xml parameter


System.Xml.XmlDocument objXMLDocument = null;

System.Xml.XmlElement objXMLElement = null;

System.Xml.XmlElement objXMLChildElement = null;


//Bulding XML Document for Statistical Ranges

objXMLDocument = new System.Xml.XmlDocument();


objXMLElement = objXMLDocument.DocumentElement;

foreach (string sItem in listBox1.SelectedItems)


	objXMLChildElement = objXMLDocument.CreateElement("packagemaster");

	objXMLChildElement.SetAttribute("Pkey" , sItem);



// pass objXMLDocument.OuterXml to Sp parameter

insertcommand.parameters.add("@vchXMLParms" , sqldbtype.varchar , 8000).value = objXMLDocument.OuterXml;	 

sample Sp


ALTER proc InsertSp(@vchXMLParms VARCHAR(MAX))



DECLARE @xmldocHandle AS INT

EXEC sp_xml_preparedocument @xmldocHandle OUTPUT, @vchXMLParms


 insert into YourTableName(packagemaster)

 SELECT Pkey FROM OPENXML(@xmldocHandle, '/root/packagemaster', 1)WITH(Pkey VARCHAR(MAX))


EXEC sp_xml_removedocument @xmldocHandle

Open in new window


Author Closing Comment

Comment Utility
im using using sql server 2005 as DB...could u tell me d solution in c# coding

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now