Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# equivalent of Appe from
Message
 
À
11/12/2007 08:27:25
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01274325
Message ID:
01274979
Vues:
13
Hi John.
Many thanks for that.
I'll have alook over the coming days and am sure it will be of assistance.
Regards,
Gerard


>>Hi John.
>>Thanks for your help.
>>I think I will end up writin g code to import the CSV file..I think its probably the cleanest and least complicated.
>>If you had any pointers on how to do this I'd appreciate it.
>>
>
>
>This is part of the import file service:
>
>
>
>        /// <summary>
>        /// Import delimited text file service.
>        /// </summary>
>        /// <param name="fileName">CSV File to Import </param>
>        /// <returns>imported datatable</returns>
>        public List<string> ImportDelimited(string fileName)
>        {
>            StreamReader sr = null;
>            List<string> list = new List<string>();
>            try
>            {
>                sr = new StreamReader(fileName);
>                while (!sr.EndOfStream)
>                {
>                    list.Add(sr.ReadLine());
>                }
>
>            }
>            catch (Exception e)
>            {
>                throw e;
>            }
>            finally
>            {
>                sr.Close();
>            }
>            return list;
>        }
>
>
>this is a sample import from a compact app I have:
>
>        /// <summary>
>        /// Load thing data to SQL
>        /// </summary>
>        /// <param name="fileName">CSV File to Import </param>
>        public void LoadThingDataToSQL(string fileName)
>        {
>            _dtThing = new ThingDataSet.ThingsDataTable();
>            ThingDataSet.ThingsRow dr = null;
>
>            try
>            {
>                BDImportService bis = new BDImportService();
>                List<string> list = bis.ImportDelimited(fileName);
>                foreach (string s in list)
>                {
>                    string[] sa = s.Split(",".ToCharArray());
>
>                    dr = _dtThing.NewThingsRow();
>                    //were grabbing the taxonomy name here, we'll translate the foreign keys
>                    //in another step.
>                    dr.Taxonomy = sa[_dtThing.TaxonomyColumn.Ordinal - 1];
>                    dr.Name = sa[_dtThing.NameColumn.Ordinal - 1];
>                    dr.Seen = Convert.ToBoolean(sa[_dtThing.SeenColumn.Ordinal-1].Equals("0") ? false : true);
>                    dr.CommonName = sa[_dtThing.CommonNameColumn.Ordinal-1];
>                    dr.ScientificName = sa[_dtThing.ScientificNameColumn.Ordinal-1];
>                    dr.SortOrder = (float)(Convert.ToDecimal(sa[_dtThing.SortOrderColumn.Ordinal - 1]));
>
>                    _dtThing.AddThingsRow(dr);
>                }
>
>                this.UpdateThingTable(_dtThing);
>
>            }
>            catch (Exception e)
>            {
>                throw e;
>            }
>        }
>
>
>Hope this helps....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform