Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi, I am using Visual Studio 2010 and SQL Server 2005. I have a tabcontainer in my webpage. In the first tab I need to upload a csv file and in the second tab I need to map csv file column names with sql server database columns. How to write the code mapping?
Please help me.
Posted 13-Feb-13 21:12pm
Edited 14-Feb-13 5:21am
v2
Comments
Kiran Susarla at 14-Feb-13 2:17am
   
What have you tried till now?
richcb at 14-Feb-13 10:22am
   
What do you mean by "map" the column names from csv to sql database?
ryanb31 at 14-Feb-13 13:38pm
   
There are a million ways to do it. What do you have so far? Nothing? Are you wanting a nice GUI or something simple? You need a design first.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
you can use first one to fill the column...
 
            StreamReader sr = new StreamReader(txtFirstFilePath.Text);
            string line = sr.ReadLine();
            string[] value = line.Split(',');
            System.Data.DataTable dt = new System.Data.DataTable();
            DataRow row;
            foreach (string dc in value)
            {
                dt.Columns.Add(new DataColumn(dc));
            }
 
For filling the data...
 

          while (!sr.EndOfStream)
            {
                value = sr.ReadLine().Split(',');
                if (value.Length == dt.Columns.Count)
                {
                    row = dt.NewRow();
                    row.ItemArray = value;
                    dt.Rows.Add(row);
                }
            }
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Well you face challenges regarding csv data with database table column mapping. I have to work similar requirement. I share my experiance to an article. You may help from that.
How-to-parse-chunk-by-chunk-a-large-CSV-file. In my problem the csv column header contain the file column list and previously in database file column is registered by user. You can follow similar approach. When you start dumping data from csv to database then you create the map. For example you create a empty datatable from user provided columns. Create data row from csv files.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100