Note that there are some explanatory texts on larger screens.

plurals
  1. POimport CSV without header row file to datatable
    primarykey
    data
    text
    <p>I have a CSV file uploaded by UploadFile control which has no header row. When I try to read it to datatable it gives the error because the first row has same values in different columns. How to insert the header row to this file or read data from CSV to datatable with predefined columns?</p> <pre><code>Data in csv: IO23968 2012 11 AB WI 100162804410W500 0 516.78 0 0 0 N 0 IO24190 2012 11 AB WI 100140604510W500 302 516.78 15617.9 0 15617 N 0 IO24107 2012 11 AB WI 100033104410W500 337 516.78 17456.3 0 17456 N 0 Control: HtmlInputFile fileOilFile = fileOilSubmission as HtmlInputFile; if (fileOilFile != null) strOilFileName = fileOilFile.Value; DataTable: DataTable csvData = new DataTable(); csvData.Columns.Add("RoyaltyEntityID", typeof(string)); csvData.Columns.Add("ProductionYear", typeof(int)); csvData.Columns.Add("ProductionMonth", typeof(int)); csvData.Columns.Add("ProductionEntityID", typeof(string)); csvData.Columns.Add("ProductionVolume", typeof(double)); csvData.Columns.Add("SalePrice", typeof(double)); csvData.Columns.Add("GrossRoyaltyAmount", typeof(double)); csvData.Columns.Add("TruckingRate", typeof(double)); csvData.Columns.Add("TotalNetRoyalty", typeof(double)); csvData.Columns.Add("ConfidentialWell", typeof(bool)); csvData.Columns.Add("HoursProductionAmount", typeof(double)); using (StreamReader sr = File.OpenText(strOilFileName)) { string s = String.Empty; while ((s = sr.ReadLine()) != null) { //we're just testing read speeds foreach (var line in strOilFileName) { csvData.Rows.Add(line.split(',')[0]); csvData.Rows.Add(line.split(',')[1]); csvData.Rows.Add(line.split(',')[2]); csvData.Rows.Add(line.split(',')[3]); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload