Updating string values into custom data xml field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • programmher
    New Member
    • Jan 2014
    • 19

    Updating string values into custom data xml field

    This might belong in the XML forum, but I am trying here first.

    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:

    Code:
    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);
    
            }
    
        }
    }
    I think I need to include something like:

    Code:
    if old.Autor != Author
     {
                   string Authorseparatedvalue = string.Empty;
                     if (Author.Length != 0)
                     {       
                    //What goes here to insert the string??   Perhaps something like this - Authorseparatedvalue = string.Join(",", (string[])Location.ToArray(typeof(string)));          }
    This definitely works for updating one author's name:
    Code:
    if (old.Author != Author) RequestItem.UpdateField(LibraryDocID, Editor, "Author", Author);
    I just can not nail down how to insert a string of author's names.
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    You will just have to pass the comma separated string containing author names using a SQL Stored procedure probably as a varchar parameter.

    You will need to call this function inside the stored procedure, to split the string and convert the values into a resultset, then you can read the data from the resultset and insert it accordingly.

    Download link for the SQL Function http://thatthatguy.in/crap/splitcommastring.zip

    Comment

    • programmher
      New Member
      • Jan 2014
      • 19

      #3
      Thatguy,
      There is an object datasource call on the page. It is here:
      Code:
      <asp:ObjectDataSource runat="server" ID="odsAuthorsDoc" SelectMethod="GetAuthorsDocByID" TypeName="Library.Media.AuthorDoc" UpdateMethod="UpdateAuthorsDoc">
              <SelectParameters>
                  <asp:QueryStringParameter Name="RequestID" QueryStringField="id" Type="Int32" />
              </SelectParameters>
              <UpdateParameters>
                  <asp:QueryStringParameter Name="AuthorDocID" Type="Int32" QueryStringField="id" />
                  <asp:ProfileParameter Name="Editor" PropertyName="RequestD" Type="Int32" />
              </UpdateParameters>
          </asp:ObjectDataSource>
      This passes all the values to the .cs I posted. Are you saying I need a separate sql stored procedure call on the page to pass in the string and can not use the objectdatasourc e update call from the tag I posted above that passes all the values to the .cs?

      Comment

      Working...