tdignan87
Well-known member
- Joined
- Jul 8, 2019
- Messages
- 95
- Programming Experience
- Beginner
Hi everyone,
I have just found this forum! looking forward to checking this place out.
I have a datagridview (unbound) that exports successfully into XML with elements. I want to however; run the XML for every line in the datagridview that contains data and treat it as a individual XML import. Basically the code to loop for the next row.
See example for code.
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
// Initialize the XmlWriter.
// Dim XmlWrt As XmlWriter = XmlWriter.Create("COMMODITY.xml", settings)
XmlWriter XmlWrt = XmlWriter.Create(ExportLocTxt.Text, settings);
{
var withBlock = XmlWrt;
// Write the Xml declaration.
withBlock.WriteStartDocument();
// Write a comment.
withBlock.WriteComment("Stevens Container Import. iSchedulr");
// Write the root element.
withBlock.WriteStartElement("stevens");
// Start our first person.
withBlock.WriteStartElement("containers");
withBlock.WriteStartElement("container");
// The person nodes.
withBlock.WriteStartElement("code");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[0].Value.ToString());
// withBlock.WriteString(row.Cells[0].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("name");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[1].Value.ToString());
// withBlock.WriteString(row.Cells[1].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("description");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[2].Value.ToString());
// withBlock.WriteString(row.Cells[2].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("tare");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[3].Value.ToString());
// withBlock.WriteString(row.Cells[3].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("type");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[5].Value.ToString());
// withBlock.WriteString(row.Cells[5].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("group");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[4].Value.ToString());
// withBlock.WriteString(row.Cells[4].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("location");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[6].Value.ToString());
// withBlock.WriteString(row.Cells[6].Value.ToString());
withBlock.WriteEndElement();
// The end of this person.
withBlock.WriteEndElement();
withBlock.WriteEndElement();
// Close the XmlTextWriter.
withBlock.WriteEndDocument();
withBlock.Close();
I have just found this forum! looking forward to checking this place out.
I have a datagridview (unbound) that exports successfully into XML with elements. I want to however; run the XML for every line in the datagridview that contains data and treat it as a individual XML import. Basically the code to loop for the next row.
See example for code.
try
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
// Initialize the XmlWriter.
// Dim XmlWrt As XmlWriter = XmlWriter.Create("COMMODITY.xml", settings)
XmlWriter XmlWrt = XmlWriter.Create(ExportLocTxt.Text, settings);
{
var withBlock = XmlWrt;
// Write the Xml declaration.
withBlock.WriteStartDocument();
// Write a comment.
withBlock.WriteComment("Stevens Container Import. iSchedulr");
// Write the root element.
withBlock.WriteStartElement("stevens");
// Start our first person.
withBlock.WriteStartElement("containers");
withBlock.WriteStartElement("container");
// The person nodes.
withBlock.WriteStartElement("code");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[0].Value.ToString());
// withBlock.WriteString(row.Cells[0].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("name");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[1].Value.ToString());
// withBlock.WriteString(row.Cells[1].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("description");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[2].Value.ToString());
// withBlock.WriteString(row.Cells[2].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("tare");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[3].Value.ToString());
// withBlock.WriteString(row.Cells[3].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("type");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[5].Value.ToString());
// withBlock.WriteString(row.Cells[5].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("group");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[4].Value.ToString());
// withBlock.WriteString(row.Cells[4].Value.ToString());
withBlock.WriteEndElement();
withBlock.WriteStartElement("location");
withBlock.WriteString(dataGridView1.CurrentRow.Cells[6].Value.ToString());
// withBlock.WriteString(row.Cells[6].Value.ToString());
withBlock.WriteEndElement();
// The end of this person.
withBlock.WriteEndElement();
withBlock.WriteEndElement();
// Close the XmlTextWriter.
withBlock.WriteEndDocument();
withBlock.Close();