XML to SQL in Orcas Beta 2

  • Thread starter Thread starter lausivcid
  • Start date Start date
L

lausivcid

Hi,

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

Thanks,
lausivcid
 
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.
 
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
 
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.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top