<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dotnet thoughts &#187; OleDb</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/oledb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Text truncated to 255 characters when reading from Excel using OLEDB</title>
		<link>http://www.dotnetthoughts.net/2010/12/31/text-truncated-to-255-characters-when-reading-from-excel-using-oledb/</link>
		<comments>http://www.dotnetthoughts.net/2010/12/31/text-truncated-to-255-characters-when-reading-from-excel-using-oledb/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 11:24:42 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Excel Import]]></category>
		<category><![CDATA[OleDb]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1355</guid>
		<description><![CDATA[Today my friend Jacob got a strange problem while importing data from EXCEL using OLEDB; he was not able to read actual values of cells, which contains more than 255 characters. The text was truncated if the cell contains more &#8230; <a href="http://www.dotnetthoughts.net/2010/12/31/text-truncated-to-255-characters-when-reading-from-excel-using-oledb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today my friend Jacob got a strange problem while importing data from EXCEL using OLEDB; he was not able to read actual values of cells, which contains more than 255 characters. The text was truncated if the cell contains more than 255. The code was like this</p>
<pre class="brush: csharp; title: ; notranslate">
OleDbConnection con = new OleDbConnection(
@&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;
+ _xlsFilePath + &quot;;Extended Properties=\&quot;Excel 8.0;HDR=YES;IMEX=1\&quot;;&quot;);
OleDbDataAdapter da = new OleDbDataAdapter
(&quot;select * from [&quot; + sheetName + &quot;$]&quot;, con);
DataTable dt = new DataTable();
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.FillSchema(dt, SchemaType.Source);
da.Fill(dt);
return dt;
</pre>
<p>We tried various options in the connection strings but nothing worked. Later we found this <a href="http://support.microsoft.com/kb/281517/en-us" target="_blank">MS Support article</a>, which helps to resolve this error using Registry Editing. This issue is because the Jet Engine reads the first 8 cells of each column and check it&#8217;s data type. </p>
<p>You can fix this problem by setting a value between 0 to 16 for the <strong>TypeGuessRows</strong> key in <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel</strong> location. If you put <strong>0</strong> as the value, Jet engine will read the first 16000 rows, which may affect the performance.</p>
<p>You can resolve this problem with code.</p>
<pre class="brush: csharp; title: ; notranslate">
RegistryKey key = Registry.LocalMachine.OpenSubKey(
@&quot;SOFTWARE\Microsoft\Jet\4.0\Engines\Excel\&quot;, true);
if (null != key)
{
key.SetValue(&quot;TypeGuessRows&quot;, 0, RegistryValueKind.DWord);
}
</pre>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/02/16/import-data-from-excel-using-c-part-2/" title="Permanent link to Import Data from Excel using C# &#8211; Part 2">Import Data from Excel using C# &#8211; Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/23/import-export-data-in-ms-excel-using-c/" title="Permanent link to Import / export data in MS Excel using C#">Import / export data in MS Excel using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/09/26/run-the-application-at-windows-startup/" title="Permanent link to Run the application at Windows startup">Run the application at Windows startup</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/02/15/how-to-associate-a-file-type-to-your-application/" title="Permanent link to How to associate a File Type to your application">How to associate a File Type to your application</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/03/argumentexception-this-row-already-belongs-to-another-table/" title="Permanent link to ArgumentException &#8211; This row already belongs to another table">ArgumentException &#8211; This row already belongs to another table</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/12/31/text-truncated-to-255-characters-when-reading-from-excel-using-oledb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import / export data in MS Excel using C#</title>
		<link>http://www.dotnetthoughts.net/2009/09/23/import-export-data-in-ms-excel-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/09/23/import-export-data-in-ms-excel-using-c/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 07:38:02 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Import /Export Excel]]></category>
		<category><![CDATA[OleDb]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=401</guid>
		<description><![CDATA[Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but Office Automation in Web servers,got some issues;(More details: http://support.microsoft.com/kb/257757). The alternative &#8230; <a href="http://www.dotnetthoughts.net/2009/09/23/import-export-data-in-ms-excel-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but Office Automation in Web servers,got some issues;(More details: <a target="_blank" href="http://support.microsoft.com/kb/257757">http://support.microsoft.com/kb/257757</a>). The alternative is using OleDb provider. You may need to add one more attribute to connection string to connect to the Excel file. And connection string will be</p>
<pre class="brush: csharp; title: ; notranslate">
string connectionString = &quot;Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:\Sample.xls; Extended Properties=Excel 8.0;&quot;
</pre>
<p>Please note the &#8220;Extended Properties&#8221; attribute. This attribute helps us to query the excel file.</p>
<p>Exporting Data from Data Table to Excel File.</p>
<pre class="brush: csharp; title: ; notranslate">
string connectionString = &quot;Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:\Sample.xls; Extended Properties=Excel 8.0;&quot;
// Establish a connection to the data source.
using(OleDbConnection Connection = new OleDbConnection(connectionString))
{
Connection.Open()
//creating a new Sheet with name sample and three columns with Heading firstname, lastname and email
using(OleDbCommand command = new OleDbCommand())
{
command.Connection = Connection;
command.CommandText = &quot;CREATE TABLE [Sample$](FirstName Char(255), LastName char(255), Email char(255))&quot;;
command.ExecuteNonQuery();
}
//Adding records to the Sample Worksheet
using(OleDbCommand command = new OleDbCommand())
{
command.Connection = Connection;
command.CommandText = &quot;INSERT INTO TABLE [Sample$](FirstName,LastName,Email) VALUES('Anuraj','P','anuraj.p@example.com')&quot;;
command.ExecuteNonQuery();
command.CommandText = &quot;INSERT INTO TABLE [Sample$](FirstName,LastName,Email) VALUES('sreekumar','vn','sreekumar.vn@example.com')&quot;;
command.ExecuteNonQuery();
}
}
</pre>
<p>Import the Data from Excel</p>
<pre class="brush: csharp; title: ; notranslate">
DataTable dt;
string connectionString = &quot;Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:\Sample.xls; Extended Properties=Excel 8.0;&quot;
// Establish a connection to the data source.
using(OleDbConnection Connection = new OleDbConnection(connectionString))
{
Connection.Open()
//reading data from excel to Data Table
using(OleDbCommand command = new OleDbCommand())
{
command.Connection = Connection;
command.CommandText = &quot;SELECT * FROM [Sample]&quot;;
using(OleDbDataAdapter adapter =new OleDbDataAdapter())
{
adapter.SelectCommand = command;
adapter.Fill(dt);
}
}
}
</pre>
<p>You can get more information from Microsoft support site<br />
<a href="http://support.microsoft.com/kb/306023" target="_blank"><br />
http://support.microsoft.com/kb/306023 &#8211; How to transfer data to an Excel workbook by using Visual C# 2005 or Visual C# .NET</a></p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/02/16/import-data-from-excel-using-c-part-2/" title="Permanent link to Import Data from Excel using C# &#8211; Part 2">Import Data from Excel using C# &#8211; Part 2</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/31/text-truncated-to-255-characters-when-reading-from-excel-using-oledb/" title="Permanent link to Text truncated to 255 characters when reading from Excel using OLEDB">Text truncated to 255 characters when reading from Excel using OLEDB</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/22/implementing-custom-paging-in-datarepeater-using-c-and-sql-server/" title="Permanent link to Implementing Custom Paging in DataRepeater using C# and SQL Server">Implementing Custom Paging in DataRepeater using C# and SQL Server</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/" title="Permanent link to How to Store and Retrieve files from SQL Server Database">How to Store and Retrieve files from SQL Server Database</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/04/27/using-multiple-active-result-sets-mars/" title="Permanent link to Using Multiple Active Result Sets (MARS)">Using Multiple Active Result Sets (MARS)</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/09/23/import-export-data-in-ms-excel-using-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

