Click here to Skip to main content
13,194,662 members (69,614 online)
Rate this:
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 20:12pm
Updated 14-Feb-13 4:21am
Kiran Susarla 14-Feb-13 2:17am
What have you tried till now?
richcb 14-Feb-13 10:22am
What do you mean by "map" the column names from csv to sql database?
ryanb31 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
Please Sign up or sign in to vote.

Solution 1

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;
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171018.2 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2017
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