Solved

unable to insert multiple listbox items in to database

Posted on 2008-09-30
3
376 Views
Last Modified: 2012-05-05
insertcommand.parameters.add("@packagemaster",sqldbtype.varchar,500).value=selectedlist.items;

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 working.....so suggest me  to handle this situation
0
Comment
Question by:life_j
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Binuth earned 500 total points
ID: 22611876
which version of DB you using ?
0
 
LVL 14

Expert Comment

by:Binuth
ID: 22611924
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();
objXMLDocument.LoadXml("<root/>");
 
objXMLElement = objXMLDocument.DocumentElement;
 
foreach (string sItem in listBox1.SelectedItems)
{
	objXMLChildElement = objXMLDocument.CreateElement("packagemaster");
	objXMLChildElement.SetAttribute("Pkey" , sItem);
	objXMLElement.AppendChild(objXMLChildElement);
}
 
// pass objXMLDocument.OuterXml to Sp parameter
insertcommand.parameters.add("@vchXMLParms" , sqldbtype.varchar , 8000).value = objXMLDocument.OuterXml;	 
 
 
sample Sp
---------
 
 
ALTER proc InsertSp(@vchXMLParms VARCHAR(MAX))
AS
 
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

0
 
LVL 7

Author Closing Comment

by:life_j
ID: 31501855
im using using sql server 2005 as DB...could u tell me d solution in c# coding
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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