Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

XML to SQL in Orcas Beta 2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lausivcid@yahoo.com - 14 Oct 2007 17:40 GMT
Hi,

  What is the best way to write XmlNodeType.Element Text into an SQL
table with identical column names?

Thanks,
lausivcid
Nicholas Paldino [.NET/C# MVP] - 15 Oct 2007 00:05 GMT
Well, you can just get the xml text using the OuterXml property on the
XmlNode and then place that in the column using a standard insert/update
command.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi,
>
[quoted text clipped - 3 lines]
> Thanks,
> lausivcid
lausivcid - 15 Oct 2007 06:02 GMT
>    Well, you can just get the xml text using the OuterXml property on the
>XmlNode and then place that in the column using a standard insert/update
>command.

Thanks, is it possible to use a string or an integer index to identify
a SQL column, in a way similar to DataGridView[string columName,int
rowIndex] or DataGridView[int columnIndex, int rowIndex] ?       I
would like to be able to do something like this:   row = new
sqlTableEntitiy(); row[xmlElementName]=xmElementText; // SQL column
[xmlElementName] is a VarChar
Nicholas Paldino [.NET/C# MVP] - 15 Oct 2007 16:01 GMT
Well, you won't be able to assign the node directly to the column value,
but you can use the OuterXml property of the node to get the xml to assign
to the column in string format.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>>    Well, you can just get the xml text using the OuterXml property on the
>>XmlNode and then place that in the column using a standard insert/update
[quoted text clipped - 6 lines]
> sqlTableEntitiy(); row[xmlElementName]=xmElementText; // SQL column
> [xmlElementName] is a VarChar
lausivcid - 15 Oct 2007 21:13 GMT
>    Well, you won't be able to assign the node directly to the column value,
>but you can use the OuterXml property of the node to get the xml to assign
>to the column in string format.

A DataGridView can bind an Entitiy table's columns, so I knew the
information was there somewhere.   Alois Kraus
http://geekswithblogs.net/akraus1/archive/2006/02/10/69047.aspx showed
me how.  Using Alois's class:

   public class PropertyInvoker<T>
   {

       private PropertyInfo propInfo;

       private object obj;

       public PropertyInvoker(string PropertyName, object o)
       {
           obj = o;
           propInfo = o.GetType().GetProperty(PropertyName);
       }

       public T Property
       {
           get
           {
               return (T)propInfo.GetValue(obj, null);
           }

           set
           {
               propInfo.SetValue(obj, value, null);
           }
       }

       public T GetProperty()
       {
           return Property;
       }

       public void SetProperty(T value)
       {
           Property = value;
       }

   } // class PropertyInvoke

I can make the function

       static void column<T>(string name,T value,entityType  entity)
       {
           (new PropertyInvoker<T>(name, entity)).SetProperty(value);

       }

column  use:

           XmlReader reader = XmlReader.Create(fn, settings);
           reader.MoveToContent();
          string name=null;
   
           while (reader.Read())
           {
               switch (reader.NodeType)
               {
                   case XmlNodeType.Element:
                       name = reader.Name;
                       break;
                   case XmlNodeType.Text:
                       column<string>(name,reader.Value,entity);
                       break;
               }
           }

Whether this way will be fast enough I don't know, I whll have up to
60k XML records to load per day.    An improvement that I might need
to make is to use this technique to do DataGridView type binding in a
class initializer.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.