EDN Admin
Well-known member
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using Microsoft.Office.Interop.Excel;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; namespace DailyTicketFinaleTesting
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; public Form1()
{
InitializeComponent();
toolStripStatusLabel1.Text = <span style="color:#A31515; "";
}
<span style="color:Blue; private DataTable ParseCSVgetDT(<span style="color:Blue; string filePath)
{
<span style="color:Blue; string[] lines = File.ReadAllLines(filePath);
DataTable dt = <span style="color:Blue; new DataTable();
dt.Columns.Add(<span style="color:#A31515; "Field0");
dt.Columns.Add(<span style="color:#A31515; "Field1");
dt.Columns.Add(<span style="color:#A31515; "Field2");
dt.Columns.Add(<span style="color:#A31515; "Field3");
dt.Columns.Add(<span style="color:#A31515; "Field4");
dt.Columns.Add(<span style="color:#A31515; "Field5");
dt.Columns.Add(<span style="color:#A31515; "Field6");
dt.Columns.Add(<span style="color:#A31515; "Field7");
dt.Columns.Add(<span style="color:#A31515; "Field8");
dt.Columns.Add(<span style="color:#A31515; "Field9");
dt.Columns.Add(<span style="color:#A31515; "Field10");
dt.Columns.Add(<span style="color:#A31515; "Field11");
dt.Columns.Add(<span style="color:#A31515; "Field12");
dt.Columns.Add(<span style="color:#A31515; "Field13");
<span style="color:Blue; string[] fields = <span style="color:Blue; new <span style="color:Blue; string[11];
<span style="color:Blue; for (<span style="color:Blue; int rows = 0; rows < lines.Length; rows++)
{
CSVRecord records = <span style="color:Blue; new CSVRecord();
fields = lines[rows].Split(<span style="color:#A31515; ,);
<span style="color:Blue; if (fields.Length >= 4)
{
dt.Rows.Add(fields[0],
fields[1],
fields[2],
fields[3],
fields[4],
fields[5],
fields[6],
fields[7],
fields[8],
fields[9],
fields[10],
fields[11],
fields[12]
);
}
}
<span style="color:Blue; return dt; <span style="color:Green; //Error
}
}<br/>
<br/>
<span style="color:Gray; ///<span style="color:Green; /Cannot implicitly convert type System.Data.DataTable to Microsoft.Office.Interop.Excel.DataTable. An explicit conversion exists (are you missing a cast?) <br/>
[/code]
Please assist to fix this error.
View the full article
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using Microsoft.Office.Interop.Excel;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; namespace DailyTicketFinaleTesting
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; public Form1()
{
InitializeComponent();
toolStripStatusLabel1.Text = <span style="color:#A31515; "";
}
<span style="color:Blue; private DataTable ParseCSVgetDT(<span style="color:Blue; string filePath)
{
<span style="color:Blue; string[] lines = File.ReadAllLines(filePath);
DataTable dt = <span style="color:Blue; new DataTable();
dt.Columns.Add(<span style="color:#A31515; "Field0");
dt.Columns.Add(<span style="color:#A31515; "Field1");
dt.Columns.Add(<span style="color:#A31515; "Field2");
dt.Columns.Add(<span style="color:#A31515; "Field3");
dt.Columns.Add(<span style="color:#A31515; "Field4");
dt.Columns.Add(<span style="color:#A31515; "Field5");
dt.Columns.Add(<span style="color:#A31515; "Field6");
dt.Columns.Add(<span style="color:#A31515; "Field7");
dt.Columns.Add(<span style="color:#A31515; "Field8");
dt.Columns.Add(<span style="color:#A31515; "Field9");
dt.Columns.Add(<span style="color:#A31515; "Field10");
dt.Columns.Add(<span style="color:#A31515; "Field11");
dt.Columns.Add(<span style="color:#A31515; "Field12");
dt.Columns.Add(<span style="color:#A31515; "Field13");
<span style="color:Blue; string[] fields = <span style="color:Blue; new <span style="color:Blue; string[11];
<span style="color:Blue; for (<span style="color:Blue; int rows = 0; rows < lines.Length; rows++)
{
CSVRecord records = <span style="color:Blue; new CSVRecord();
fields = lines[rows].Split(<span style="color:#A31515; ,);
<span style="color:Blue; if (fields.Length >= 4)
{
dt.Rows.Add(fields[0],
fields[1],
fields[2],
fields[3],
fields[4],
fields[5],
fields[6],
fields[7],
fields[8],
fields[9],
fields[10],
fields[11],
fields[12]
);
}
}
<span style="color:Blue; return dt; <span style="color:Green; //Error
}
}<br/>
<br/>
<span style="color:Gray; ///<span style="color:Green; /Cannot implicitly convert type System.Data.DataTable to Microsoft.Office.Interop.Excel.DataTable. An explicit conversion exists (are you missing a cast?) <br/>
[/code]
Please assist to fix this error.
View the full article