Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Updated 14-Feb-13 4:21am
v2
Comments
Kiran Susarla 14-Feb-13 2:17am    
What have you tried till now?
Richard C Bishop 14-Feb-13 10:22am    
What do you mean by "map" the column names from csv to sql database?
ZurdoDev 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.

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);
      }
  }
 
Share this answer
 
v3
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900