So I’ve got a excel sheet table and a mssql table, and the two are being joined on excel table column 0 (first) and mssql column textfield2, using LINQ.
The problem I’m having when it’s joining alphanumeric values, which doesn’t seem to work. It does work when the values are numeric.
var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excconnectionstring);
var adapter2 = new SqlDataAdapter("SELECT * FROM Table1", sqlconnectionstring);
var ds = new DataSet();
adapter.Fill(ds, "excel");
adapter2.Fill(ds, "sql");
var excel = ds.Tables["excel"].AsEnumerable();
var esqel = ds.Tables["sql"].AsEnumerable();
var query = from exc in excel
from sql in esqel
where exc[0].ToString() == sql.Field<string>("textfield2")
select new
{
debnr = sql.Field<string>("debnr"),
bedrag = double.Parse(exc[5].ToString())/100,
description = DateTime.Parse(exc[7].ToString(), new CultureInfo("nl-NL")).ToString("MMM yyyy"),
text1 = exc[0].ToString(),
projectno = sql.Field<string>("textfield1"),
central = sql.Field<string>("CentralizationAccount").Trim()
};
edit: Seems the alphanumeric do work when I order the values in the excel sheet with the alphanumeric values on top. But then I have the problem that it doesn’t work on the numeric values..
As others have said, the problem occurred due to the OleDb infering the column type based on the first couple of rows. Using Interop TextToColumn I change the excel column data type to Text. Here’s the code I use to do that: