<?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>TechBlog &#187; ADO</title>
	<atom:link href="http://techblog.byllemos.com/tag/ado/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.byllemos.com</link>
	<description>Accelerating into the Future with Wisdom about Technology! Ingrid Byllemos</description>
	<lastBuildDate>Tue, 05 Jan 2010 00:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Importing Image from a non Navision table to a Navision blob field</title>
		<link>http://techblog.byllemos.com/2008/05/importing-image-from-a-non-navision-table-to-blob-field/</link>
		<comments>http://techblog.byllemos.com/2008/05/importing-image-from-a-non-navision-table-to-blob-field/#comments</comments>
		<pubDate>Mon, 12 May 2008 19:33:33 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=66</guid>
		<description><![CDATA[<p>In SQL it is possible to define tables with a column, which is of type image. This field type is not known by Navision or by ADO and can thereby not be extracted like other fields.<br /><br /></p>
<p>There exists 2 ways&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>In SQL it is possible to define tables with a column, which is of type image. This field type is not known by Navision or by ADO and can thereby not be extracted like other fields.<br/><br/></p>
<p>There exists 2 ways to get this fields value.<br/></p>
<p>1) One way is to stream the image to a file and then afterwards import it into the blob.<br/><br/><br />
<span id="more-66"></span><br />
In this example I assume you already have the ADO Connection and thereby already got the ADORecordSet.<br/><br/><br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">ADOStream.Type := <span style="">1</span>; //1 = Binary
ADOStream.Open;
ADOStream.Write<span class="br0">&#40;</span>ADORecordSet.Fields.Item<span class="br0">&#40;</span>FieldName<span class="br0">&#41;</span>.Value<span class="br0">&#41;</span>;
ADOStream.SaveToFile<span class="br0">&#40;</span>'c:\tmp.bmp',2<span class="br0">&#41;</span>; //2 = SaveCreateOverWrite
ReturnTable.Picture.IMPORT<span class="br0">&#40;</span>'c:\tmp.bmp'<span class="br0">&#41;</span>;
ADOStream.Close;
CLEAR<span class="br0">&#40;</span>ADOStream<span class="br0">&#41;</span>;
&nbsp;
Where ADOStream is 'Microsoft ActiveX Data Objects <span style="">2.8</span> Library'.Stream
and ADORecordSet is 'Microsoft ActiveX Data Objects <span style="">2.8</span> Library'.Recordset
</div></pre><!--END_DEVFMTCODE--><br />
<br/><br />
This method works for compressed and uncompressed Blob fields.<br />
<br/><br/><br />
2) Another way is to move/insert the image into your table by using ADO RecordSet.<br />
<br/><br/><br />
Create 2 connections, one to your image table (ADOConn) and one to the table in Navision (NAVconn) where you want the picture to be inserted. Then &#8220;transfer&#8221; the Value from one RecordSet to another and add it.<br/><br/></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">FromRecSet := ADOConn.Execute<span class="br0">&#40;</span>'SELECT image FROM tableX','',0<span class="br0">&#41;</span>;
FromRecSet.MoveFirst;
&nbsp;
//The following query is used to get a &quot;blank&quot; recordset, just like a INIT in Navision
MyQuery := 'SELECT <span class="br0">&#91;</span>EntryNo<span class="br0">&#93;</span>, <span class="br0">&#91;</span>Picture<span class="br0">&#93;</span> FROM <span class="br0">&#91;</span>MyTable<span class="br0">&#93;</span> WHERE <span class="br0">&#91;</span>EntryNo<span class="br0">&#93;</span> = 0';
&nbsp;
NewRecSet.Open<span class="br0">&#40;</span>MyQuery,NAVconn,1,3,1<span class="br0">&#41;</span>;
NewRecSet.AddNew;
NewRecSet.Fields.Item<span class="br0">&#40;</span>'Picture'<span class="br0">&#41;</span>.Value := FromRecSet.Fields.Item<span class="br0">&#40;</span>'image'<span class="br0">&#41;</span>.Value;
NewRecSet.Update;
&nbsp;
</div></pre><!--END_DEVFMTCODE--><br />
<br/><br />
This method does not work for compressed Blob fields!<br />
<br/><br/><br />
If you need to know more about <a href="http://techblog.byllemos.com/?p=38">ADO Connection</a> or <a href="http://techblog.byllemos.com/?p=40">ADO RecordSet</a>, then please read my previous posts on <a title="ADO" href="http://techblog.byllemos.com/?s=ADO">ADO</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/05/importing-image-from-a-non-navision-table-to-blob-field/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ADORecordSet</title>
		<link>http://techblog.byllemos.com/2008/02/ado-properties-adorecordset/</link>
		<comments>http://techblog.byllemos.com/2008/02/ado-properties-adorecordset/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:36:12 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=40</guid>
		<description><![CDATA[<p>Hi !</p>
<p>This is a detailed description for the used ADORecordSet command mentioned in the articles <a href="http://techblog.byllemos.com//?p=29" target="_blank" title="Stored Procedures and Navision"><em>Stored Procedures and Navision</em></a> and <a href="http://techblog.byllemos.com//?p=28" target="_blank" title="ADO in Navision"><em>ADO in Navision</em></a>.</p>
<h2>ADORecordSet</h2>
<p>The ADO RecordSet is&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hi !</p>
<p>This is a detailed description for the used ADORecordSet command mentioned in the articles <a href="http://techblog.byllemos.com//?p=29" target="_blank" title="Stored Procedures and Navision"><em>Stored Procedures and Navision</em></a> and <a href="http://techblog.byllemos.com//?p=28" target="_blank" title="ADO in Navision"><em>ADO in Navision</em></a>.</p>
<h2>ADORecordSet</h2>
<p>The ADO RecordSet is defined by the automation &#8216;Microsoft ActiveX Data Objects Recordset 2.8 Library&#8217;.Recordset or by &#8216;Microsoft ActiveX Data Objects 2.8 Library&#8217;.Recordset</p>
<p>It is used to hold a set of records from a from a database table or a defined query. The Recordset object contains rows and columns (fields).<br />
<span id="more-40"></span><br />
In the mentioned articles we are using the following ADORecordSet methods:</p>
<h3>ADORecordset.ActiveConnection</h3>
<p>Sets the definition for the current connection.</p>
<h3>ADORecordSet.Close</h3>
<p>Closes a RecordSet.</p>
<h3>ADORecordSet.EOF</h3>
<p>Returns true if the recordset is at the end of the buffered response (after the last record), otherwise it is false.</p>
<h3>ADORecordSet.Fields.Item(&#8216;Name&#8217;).Value</h3>
<p>Returns a specific Items value. Fields are a collection of Items.</p>
<h3>ADORecordSet.MoveFirst</h3>
<p>Go to the first Record in the RecordSet.</p>
<h3>ADORecordSet.MoveNext</h3>
<p>Go the next record in the RecordSet.</p>
<h3>ADORecordset.Open</h3>
<p>Opens a connection to a database element, which gives access to records in a table, query results or saved recordsets.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/ado-properties-adorecordset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADOCommand</title>
		<link>http://techblog.byllemos.com/2008/02/ado-properties-adocommand/</link>
		<comments>http://techblog.byllemos.com/2008/02/ado-properties-adocommand/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:16:06 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=39</guid>
		<description><![CDATA[<p>This is a detailed description for the used ADOCommand command in the articles <a href="http://techblog.byllemos.com//?p=29" target="_blank" title="Stored Procedures and Navision"><em>Stored Procedures and Navision</em></a> and <a href="http://techblog.byllemos.com//?p=28" target="_blank" title="ADO in Navision"><em>ADO in Navision</em></a>.</p>
<h2>ADOCommand</h2>
<p>The ADO Command is defined by the&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>This is a detailed description for the used ADOCommand command in the articles <a href="http://techblog.byllemos.com//?p=29" target="_blank" title="Stored Procedures and Navision"><em>Stored Procedures and Navision</em></a> and <a href="http://techblog.byllemos.com//?p=28" target="_blank" title="ADO in Navision"><em>ADO in Navision</em></a>.</p>
<h2>ADOCommand</h2>
<p>The ADO Command is defined by the automation ‘Microsoft ActiveX Data Objects 2.8 Library’.Command<br />
It is used to execute a query against a database.<br />
<span id="more-39"></span><br />
In the mentioned articles we are using the following ADOCommand methods:</p>
<h3>ADOCommand.ActiveConnection</h3>
<p>Sets the definition for the current connection.</p>
<h3>ADOCommand.CommandText</h3>
<p>The provider command. Is often either a sql query script or a stored procedure.</p>
<p>Sql query script example: ADOCommand.CommandText := ‘SELECT count(*) FROM [Customers]’;</p>
<p>Stored Procedure example: ADOCommand.CommandText := ‘[SP_CountCustomers]’;</p>
<h3>ADOCommand.CommandType</h3>
<p>The type of command, that is being executed with the CommandText.</p>
<p>Valid values are:</p>
<p><center></p>
<table height="130" width="90%">
<tr>
<td align="center" width="80">-1</td>
<td width="120">adCmdUnspecified</td>
<td>Command type argument not specified</td>
</tr>
<tr>
<td align="center">1</td>
<td>adCmdText</td>
<td>CommandText is a sql query script</td>
</tr>
<tr>
<td align="center">2</td>
<td>adCmdTable</td>
<td>CommandText is a table name whose columns are all returned by an internally generated SQL query</td>
</tr>
<tr>
<td align="center">4</td>
<td>adCmdStoredProc</td>
<td>CommandText is a stored procedure name</td>
</tr>
<tr>
<td align="center">8</td>
<td>adCmdUnknown</td>
<td>Type of command in the CommandText property is unknown.</td>
</tr>
<tr>
<td align="center">256</td>
<td>adCmdFile</td>
<td>CommandText is the file name of a persistently stored Recordset</td>
</tr>
<tr>
<td align="center">512</td>
<td>adCmdTableDirect</td>
<td>CommandText is a table name whose columns are all returned</td>
</tr>
</table>
<p></center></p>
<h3>ADOCommand.CommandTimeout</h3>
<p>No. of seconds to wait while trying to execute a command.</p>
<h3>ADOCommand.CreateParameter</h3>
<p>Creates a Parameter object. Is often used when calling Stored Procedures, where parameters are required.It takes the parameters name, type, direction, size and value.</p>
<ul>
<li>name is the name of the parameter object</li>
<li>type specifies the data type for the object</li>
<li>direction defines the direction of the parameter &#8211; in or out</li>
<li>size specifies the length of a variable data type</li>
<li>value is value of the parameter object</li>
</ul>
<p>Example on types are:</p>
<ul>
<li>adBoolean (11) &#8211; indicates an boolean value</li>
<li>adBSTR (8) &#8211; indicates a null-terminated character string</li>
<li>adDate (7) &#8211; indicates a date value</li>
<li>adDecimal (14)</li>
<li>ad Numeric (131)</li>
</ul>
<p>The complete list can be seen <a href="http://msdn2.microsoft.com/en-us/library/ms675318(VS.85).aspx" target="_blank" title="MSDN">here</a>.</p>
<h3>ADOCommand.Execute</h3>
<p>Executes the query, sql statement or procedure stated in the CommandText</p>
<h3>ADOCommand.Parameters.Append(ADOParameter);</h3>
<p>Appends the parameters created by the CreateParameter command.</p>
<p>Parameters contains all the parameters of a command object.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/ado-properties-adocommand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADOConnection</title>
		<link>http://techblog.byllemos.com/2008/02/ado-properties-adoconnection/</link>
		<comments>http://techblog.byllemos.com/2008/02/ado-properties-adoconnection/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:06:22 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=38</guid>
		<description><![CDATA[<p>Hi !</p>
<p>I have been asked to describe the different ADO commands parameters more explicit. So here are a detailed description for the used ADOconnection command in the articles <a href="http://techblog.byllemos.com/?p=29" title="Stored Procedures and Navision" target="_blank"><em>Stored Procedures and Navision</em></a> and&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hi !</p>
<p>I have been asked to describe the different ADO commands parameters more explicit. So here are a detailed description for the used ADOconnection command in the articles <a href="http://techblog.byllemos.com/?p=29" title="Stored Procedures and Navision" target="_blank"><em>Stored Procedures and Navision</em></a> and <a href="http://techblog.byllemos.com/?p=28" title="ADO in Navision" target="_blank"><em>ADO in Navision</em></a>.</p>
<h2>ADOconnection</h2>
<p>ADOconnection is defined by the automation ‘Microsoft ActiveX Data Objects 2.8 Library’.Connection<br />
It is used to create and open a connection to a data source (database).<br />
<span id="more-38"></span><br />
In the mentioned articles we are using the following ADOconnection methods:</p>
<h3>ADOconnection.Close</h3>
<p>Closes a connection</p>
<h3>ADOConnection.ConnectionString</h3>
<p>Sets the details used for making a connection. It includes information about provider, server, database, userid and password.<br />
Ex.<code> '</code>PROVIDER=SQLOLEDB;SERVER=SQLServer;DATABASE=SQLDatabase;UID=SQLUserID;PWD=SQLPwd<code>'</code></p>
<h3>ADOConnection.Execute</h3>
<p>Executes a query statement or a procedure. It takes the parameters commandtext, recordsaffected and option.</p>
<ul>
<li>Commandtext is a sql query statement or a call to a stored procedure.</li>
<li>Recordsaffected returns the no. of records affected by the query.</li>
<li>Option is used to set how the provider should evaluate the commandtext parameters.</li>
</ul>
<p>Valid option values are:<br />
<center></p>
<table height="130" width="90%">
<tr>
<td align="center" width="80">-1</td>
<td width="120">adCmdUnspecified</td>
<td>Command type argument not specified</td>
</tr>
<tr>
<td align="center">1</td>
<td>adCmdText</td>
<td>CommandText is a sql query script</td>
</tr>
<tr>
<td align="center">2</td>
<td>adCmdTable</td>
<td>CommandText is a table name whose columns are all returned by an internally generated SQL query</td>
</tr>
<tr>
<td align="center">4</td>
<td>adCmdStoredProc</td>
<td>CommandText is a stored procedure name</td>
</tr>
<tr>
<td align="center">8</td>
<td>adCmdUnknown</td>
<td>Type of command in the CommandText property is unknown.</td>
</tr>
<tr>
<td align="center">256</td>
<td>adCmdFile</td>
<td>CommandText is the file name of a persistently stored Recordset</td>
</tr>
<tr>
<td align="center">512</td>
<td>adCmdTableDirect</td>
<td>CommandText is a table name whose columns are all returned</td>
</tr>
</table>
<p></center><br />
ADOConnection returns a recordset.Ex. ADORecordSet := ADOConnection.Execute(SQLString,RecordsAffected,Option)</p>
<h3>ADOConnection.Open</h3>
<p>Opens a connection. If connectionsstring is not set, it can be used in the open command as a paramenter.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/ado-properties-adoconnection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stored Procedures and Navision</title>
		<link>http://techblog.byllemos.com/2008/02/store-procedures-and-navision/</link>
		<comments>http://techblog.byllemos.com/2008/02/store-procedures-and-navision/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 23:07:46 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Stored Procedures]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=29</guid>
		<description><![CDATA[<p>If you are executing a specific SQL query very often, it would be usefully to have it as Stored Procedure on the SQL Server.</p>
<p>Stored Procedures is a collection of SQL statements.</p>
<p>There are 2 ways to create a store&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>If you are executing a specific SQL query very often, it would be usefully to have it as Stored Procedure on the SQL Server.</p>
<p>Stored Procedures is a collection of SQL statements.</p>
<p>There are 2 ways to create a store procedure:</p>
<ol>
<li>In the SQL Server Management Studio &#8211; you can right click on Stored Procedures and chose to create a new  Stored Procedure. It will then create a template for you, which you just have to fill out and execute</li>
<li>The second way is to build a script by yourself</li>
</ol>
<p><span id="more-29"></span><br />
A script to create a Stored Procedure could look like this:</p>
<blockquote><p> SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
&#8211; =============================================<br />
&#8211; Author:          Ingrid Byllemos<br />
&#8211; Create date:<br />
&#8211; Description:    Test of SP<br />
&#8211; =============================================<br />
CREATE PROCEDURE Count_Calls<br />
&#8211; Add the parameters for the stored procedure here<br />
@FromDate DateTime,<br />
@ToDate DateTime<br />
AS<br />
BEGIN<br />
&#8211; SET NOCOUNT ON added to prevent extra result sets from<br />
&#8211; interfering with SELECT statements.<br />
SET NOCOUNT ON;</p>
<p>&#8211; Insert statements for procedure here<br />
SELECT COUNT(*) FROM [Call]<br />
WHERE [Start Date] BETWEEN @FromDate and @ToDate</p>
<p>END<br />
GO</p></blockquote>
<p>When the script first is created, then simply execute it and a stored procedure is created on the SQL server.</p>
<p>Let us now take a look on how to use the stored procedure from Navision. Here we will be using <a href="http://techblog.byllemos.com/?p=28" title="ADO" target="_blank">ADO</a> as described in an earlier article.</p>
<p>It is a bit difference from earlier described. First you have to open the connection to the SQL server:</p>
<blockquote><p> CREATE(ADOConnection);</p>
<p>ConnectionString := <code>'</code>PROVIDER=SQLOLEDB;SERVER=SQLServer;DATABASE=SQLDatabase;<code>'</code>+<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace><code>'</code>UID=SQLUserID;PWD=SQLPwd<code>'</code>;<br />
ADOConnection.ConnectionString(ConnectionString);<br />
ADOConnection.Open;</p></blockquote>
<p>This you should already have known how to do. Now we have to setup and open a ADO Command.</p>
<p>First we create the ADO Command and sets the ActiveConnection. Notice we use a Variant to transfer the connection from ADOConnection to ADOCommand.</p>
<blockquote><p> CREATE(ADOCommand);</p>
<p>ActiveConnection := ADOConnection;<br />
//ActiveConnection is type Variant</p>
<p>ADOCommand.ActiveConnection := ActiveConnection;</p></blockquote>
<p>Next we have to setup the actual stored procedure, which has to  be executed:</p>
<blockquote><p> ADOCommand.CommandText := &#8216;[Count_Calls]&#8216;;<br />
ADOCommand.CommandType := 4;<br />
ADOCommand.CommandTimeout := 0;</p></blockquote>
<p>And the add Parameters to the command:</p>
<blockquote><p>ADOParameter := ADOCommand.CreateParameter(&#8216;@FromDate&#8217;,7,1,0,&#8217;05-01-2007&#8242;);<br />
ADOCommand.Parameters.Append(ADOParameter);</p>
<p>ADOParameter := ADOCommand.CreateParameter(&#8216;@ToDate&#8217;,7,1,0,&#8217;13-01-2007&#8242;);<br />
//(name = @ToDate,type = 7 (date), direction = 1 (in), size = 0 (default), value = &#8217;13-01-2007&#8242;)</p>
<p>ADOCommand.Parameters.Append(ADOParameter);</p></blockquote>
<p>Notice we are using CreateParameter to add the parameters to the command.</p>
<p>Now execute the command and fetch the query result into a recordset:</p>
<blockquote><p> ADOCommand.Execute;</p>
<p>CREATE(ADORecordset);<br />
ADORecordset.ActiveConnection := ADOConnection;<br />
ADORecordset.Open(ADOCommand);<br />
ADORecordset.MoveFirst;</p>
<p>MESSAGE(FORMAT(ADORecordset.Fields.Item(0).Value));</p></blockquote>
<p>Finally close the connection:</p>
<blockquote><p> ADORecordset.Close;<br />
ADOConnection.Close;<br />
CLEAR(ADOConnection);</p></blockquote>
<p>In the example we have been using the following automations:</p>
<ul>
<li> &#8216;Microsoft ActiveX Data Objects 2.8 Library&#8217;.Connection</li>
<li> &#8216;Microsoft ActiveX Data Objects 2.8 Library&#8217;.Command</li>
<li> &#8216;Microsoft ActiveX Data Objects 2.8 Library&#8217;.Parameter</li>
<li> &#8216;Microsoft ActiveX Data Objects Recordset 2.8 Library&#8217;.Recordset</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/store-procedures-and-navision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ADO in Navision</title>
		<link>http://techblog.byllemos.com/2008/02/ado-in-navision/</link>
		<comments>http://techblog.byllemos.com/2008/02/ado-in-navision/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 21:50:15 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=28</guid>
		<description><![CDATA[<p>With ADO you can execute SQL Scripts and Stored Procedures from Navision.</p>
<p>To use ADO in Navision, you have to use the automation &#8220;Microsoft ActiveX Data Objects 2.8 Library&#8221;</p>
<p>Lets take a closer on how to make a SQL connection&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>With ADO you can execute SQL Scripts and Stored Procedures from Navision.</p>
<p>To use ADO in Navision, you have to use the automation &#8220;Microsoft ActiveX Data Objects 2.8 Library&#8221;</p>
<p>Lets take a closer on how to make a SQL connection and perform a SQL Query in Navision.</p>
<p><span id="more-28"></span></p>
<p>First you have to make a connection to the SQL Server:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">ConnectionString := 'PROVIDER=SQLOLEDB;SERVER=SQLServer;DATABASE=SQLDatabase;UID=SQLUserID;PWD=SQLPwd';
&nbsp;
ADOConnection.ConnectionString<span class="br0">&#40;</span>ConnectionString<span class="br0">&#41;</span>;
ADOConnection.Open;
&nbsp;
where ADOConnection is defined as 'Microsoft ActiveX Data Objects <span style="">2.8</span> Library'.Connection</div></pre><!--END_DEVFMTCODE--><br />
</p>
<p>Now you have a open connection to the SQL Server and are ready to execute scripts.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">    
SQLString := 'SELECT <span class="br0">&#91;</span>Name<span class="br0">&#93;</span>,<span class="br0">&#91;</span>Customer No_<span class="br0">&#93;</span> as CustomerNo ' +
             'FROM <span class="br0">&#91;</span>Customer<span class="br0">&#93;</span> WHERE <span class="br0">&#91;</span>Customer No_<span class="br0">&#93;</span> &lt; 100';
&nbsp;
ADORecordSet := ADOConnection.Execute<span class="br0">&#40;</span>SQLString,RecordsAffected,RSOption<span class="br0">&#41;</span>;
&nbsp;
</div></pre><!--END_DEVFMTCODE--><br />
</p>
<p>Where ADORecordSet is defined as &#8220;Microsoft ActiveX Data Objects 2.8 Library&#8217;.Recordset&#8221;, RecordsAffected returns the number of records fetched and RSOption sets how the provider should evaluate the commandtext parameter (SQLString).</p>
<p>Now that the query has been performed, the query result is returned into a the ADO RecordSet. Which now can be parsed.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">ADORecordSet.MoveFirst;
REPEAT
   TmpTable.Name := ADORecordSet.Fields.Item<span class="br0">&#40;</span>'Name'<span class="br0">&#41;</span>.Value;
   TmpTable.&quot;No.&quot; := ADORecordSet.Fields.Item<span class="br0">&#40;</span>'CustomerNo'<span class="br0">&#41;</span>.Value;
   TmpTable.INSERT;
   ADORecordSet.MoveNext;
UNTIL ADORecordSet.EOF;</div></pre><!--END_DEVFMTCODE--></p>
<p>When you are done using the ADORecordSet and the ADOconnetion, you have to close them:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">ADORecordSet.Close;
ADOconnection.Close;</div></pre><!--END_DEVFMTCODE--></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/ado-in-navision/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

