Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 185171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:25:23+00:00 2026-05-11T15:25:23+00:00

I know it’s not sporting asking for this kind of help, But I’ve been

  • 0

I know it’s not sporting asking for this kind of help, But I’ve been really stuck on this for a while – right now I am reading two C# books and working everyday over 9 hours.

Okay here is my problem: I have a WinForms C# application that is almost complete. In SQL I have three tables that look like this:

CREATE TABLE [dbo].[Racuni]( [BROJ] [varchar](12) NULL, [DATUM] [datetime] NULL, [TS] [datetime] NULL, [USER_ID] [int] NULL, [KASA_ID] [varchar](3) NULL, [TOTAL] [float] NULL, [STATUS] [varchar](1) NULL, [ARH] [varchar](max) NULL  ) ON [PRIMARY]  Create Table 'Rac_Npl'  ( br_rac Char( 12 ) , kasa_id Char( 3 ) , npl_id Integer , iznos Money);  CREATE TABLE [dbo].[Stavke]( [br_rac] [varchar](12) NULL, [kasa_id] [char](3) NULL, [art_id] [int] NULL, [kol] [float] NULL, [mpc] [money] NULL, [ompc] [money] NULL) 

And I have XML file(s) on local disk for importing these three tables – the XML looks like this:

<?xml version='1.0' encoding='windows-1250'?> <transaction> <table name='qryRacuniSmjene'> <fields> <field name='BROJ' type='1' size='12'/> <field name='DATUM' type='9' size='0'/> <field name='TS' type='11' size='0'/> <field name='USER_ID' type='3' size='0'/> <field name='KASA_ID' type='1' size='3'/> <field name='TOTAL' type='8' size='4'/> <field name='STATUS' type='1' size='1'/> <field name='ARH' type='16' size='1'/> </fields> <data> <row> <![CDATA[09-0002-0001]]> <![CDATA[16.04.2009]]> <![CDATA[16.04.2009 13:23:27]]> <![CDATA[1]]> <![CDATA[001]]> <![CDATA[2,60]]> <![CDATA[D]]> <![CDATA[    porezni broj: 000000000000    Zaobilaznica bb ]]> </row> <row> <![CDATA[09-0002-0002]]> <![CDATA[16.04.2009]]> <![CDATA[16.04.2009 13:23:27]]> <![CDATA[1]]> <![CDATA[001]]> <![CDATA[2,60]]> <![CDATA[D]]> <![CDATA[    porezni broj: 000000000001    Zaobilaznica bb ]]> </row> </data> </table> <table name='qryRac_nplSmjene'> <fields> <field name='br_rac' type='1' size='12'/> <field name='kasa_id' type='1' size='3'/> <field name='npl_id' type='3' size='0'/> <field name='iznos' type='8' size='4'/> </fields> <data> <row> <![CDATA[09-0002-0001]]> <![CDATA[001]]> <![CDATA[1]]> <![CDATA[2,60]]> </row> <row> <![CDATA[09-0002-0002]]> <![CDATA[001]]> <![CDATA[1]]> <![CDATA[2,60]]> </row> </data> </table> <table name='qryStavkeSmjene'> <fields> <field name='br_rac' type='1' size='12'/> <field name='kasa_id' type='1' size='3'/> <field name='art_id' type='3' size='0'/> <field name='kol' type='6' size='0'/> <field name='mpc' type='8' size='4'/> <field name='ompc' type='8' size='4'/> </fields> <data> <row> <![CDATA[09-0002-0001]]> <![CDATA[001]]> <![CDATA[152414]]> <![CDATA[1,000]]> <![CDATA[2,60]]> <![CDATA[2,60]]> </row> <row> <![CDATA[09-0002-0001]]> <![CDATA[001]]> <![CDATA[152414]]> <![CDATA[1,000]]> <![CDATA[2,60]]> <![CDATA[2,60]]> </row> </data> </table> </transaction> 

Once again I am embarassed to request assistance in this way, but I’ll try to suport StackOverflow in any way I can.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:25:24+00:00Added an answer on May 11, 2026 at 3:25 pm

    Multiple CDATA elements are not consistantly supported across implementations. For example, you will have problems accessing them an XDocument or via SelectNodes. If you can change the input format that would make things easier.

    This code hasn’t been tested and there’s no error handling or bad data checking, but it should get you started. Investigate using XPathDocument / XPathNavigator for performance and read my inline comments.

    class XmlCsvImport {     public void ImportData(string xmlData, ConnectionStringSettings connectionSettings)     {         DbProviderFactory providerFactory = DbProviderFactories.GetFactory(connectionSettings.ProviderName);          IDbConnection connection = providerFactory.CreateConnection();         connection.ConnectionString = connectionSettings.ConnectionString;          // TODO: Begin transaction          XmlDocument doc = new XmlDocument();         doc.LoadXml(xmlData);          foreach (XmlNode tableNode in doc.SelectNodes('/transaction/table'))         {             IDbCommand command = CreatCommand(connection, tableNode);              foreach (XmlNode rowNode in tableNode.SelectNodes('data/row'))             {                 string[] values = GetRowValues(rowNode);                  if (values.Length != command.Parameters.Count)                 {                     // TODO: Log bad row                     continue;                 }                  this.FillCommand(command, values);                 command.ExecuteNonQuery();             }         }          // TODO: Commit transaction     }      private IDbCommand CreatCommand(IDbConnection connection, XmlNode tableNode)     {         string tableName = tableNode.Attributes['name'].Value;          IDbCommand command = connection.CreateCommand();         command.Connection = connection;         command.CommandType = CommandType.Text;          XmlNodeList fieldNodes = tableNode.SelectNodes('fields/field');          List<string> fieldNameList = new List<string>(fieldNodes.Count);          foreach (XmlNode fieldNode in tableNode.SelectNodes('fields/field'))         {             string fieldName = fieldNode.Attributes['name'].Value;             int fieldType = Int32.Parse(fieldNode.Attributes['type'].Value);             int fieldSize = Int32.Parse(fieldNode.Attributes['size'].Value);              IDbDataParameter param = command.CreateParameter();             param.ParameterName = String.Concat('@', fieldNode.Attributes['name']);             param.Size = fieldSize;             param.DbType = (DbType)fieldType; // NOTE: this may not be so easy             command.Parameters.Add(param);              fieldNameList.Add(fieldName);         }          string[] fieldNames = fieldNameList.ToArray();          StringBuilder commandBuilder = new StringBuilder();         commandBuilder.AppendFormat('INSERT INTO [{0}] (', tableName);          string columnNames = String.Join('], [', fieldNames);         string paramNames = String.Join(', @', fieldNames);          command.CommandText = String.Concat(             'INSERT INTO [', tableName, '] ([',             columnNames,             ']) VALUES (@',             paramNames,             ')'             );          return command;     }      private string[] GetRowValues(XmlNode row)     {         List<string> values = new List<string>();          foreach (XmlNode child in row.ChildNodes)         {             if (child.NodeType == XmlNodeType.Text ||                 child.NodeType == XmlNodeType.CDATA)             {                 values.Add(child.Value);             }         }          return values.ToArray();     }      private void FillCommand(IDbCommand command, string[] values)     {         for (int i = 0; i < values.Length; i++)         {             IDbDataParameter param = (IDbDataParameter)command.Parameters[i];             param.Value = values[i]; // TODO: Convert to correct data type         }     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there has been one question about this but it is not
Know this might be rather basic, but I been trying to figure out how
I know that this sort of question has been asked here before, but still
I know the meaning of this error, but I'm really struggling with it, and
I know this is a stupid question, but I've looked for 45 mins now
I know this has been asked but I am unable to fix it For
I know that this has been discussed thousand times but I still cannot figure
I know this question has been around, but I found answers a bit foggy,
I know this has been asked a million times, but I haven't had much
I know this has been answered in other questions, but nothing is working for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.