Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a variable named Authors. Sometimes I will insert one author into the database, sometimes more than one author will be inserted into the database.

The page that performs the update is a .cs page. Here is the layout:
C#
using System; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using System.Linq; 
using System.Text; 
using System.Xml;    
  
namespace Library.Requests 
{ 
    public class LibraryDoc : RequestItem 
    { 
        private _Author; 
  
        public Author { get { return _end; } } 
        public DateTime StartDate { get { return _start; } } 
        public LibraryDoc() 
            : base() 
        { 
  
        } 
  
        public LibraryDoc(Int32 RequestID) 
            : base(ItemID) 
        { 
            XmlElement root = _doc.DocumentElement; 
            XmlNode node; 
  
            node = root.SelectSingleNode("Author"); 
            if (node != null) this._author = node.InnerText; 
  
        public LibraryDoc(Int32 RequestID, String Title, Int32 RequestedBy, String Author) 
            : base(RequestID, Title, CreatedBy, 10, Description) 
        { 
            this._Author = author 
  
            XmlDocument xml = new XmlDocument(); 
            XmlNode root = xml.CreateElement("fields"); 
            xml.AppendChild(root); 
  
            node = xml.CreateElement("Author"); 
            node.AppendChild(xml.CreateTextNode(this.Author)); 
            root.AppendChild(node); 
  
  
            //now write everything to SQL 
            this.WriteXml(xml); 
        } 
  
        public static LibraryDoc GetAuthorDocByID(Int32 RequestID) 
        { 
            return new LibraryDoc(RequestID); 
        } 
  
        public static void UpdateLibraryDoc(Int32 LibraryDocID, String Author) 
        { 
            LibraryDoc old = LibraryDoc.GetLibraryDocByID(LibraryDocID); 
            if (old.Author != Author) RequestItem.UpdateField(LibraryDocID, Editor, "Author", Author); 
  
        } 
  
    } 
} 


The last line works when I have just one author to update. I just can not nail down how to insert a string of author's names. What do I need to add to insert a comma delimited string of authors' names?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900