<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4234856802821028105</atom:id><lastBuildDate>Thu, 29 Aug 2024 05:54:17 +0000</lastBuildDate><category>.NET Programming</category><category>VB.NET</category><category>C#.NET</category><category>SQL Server</category><category>ASP .NET 1.1</category><category>ASP .NET 2.0</category><category>HTML</category><category>MS Excel</category><category>Windows</category><title>Programming Sharing Library</title><description>Sharing programming and database problems and skills&#xa;(VB.NET, C#.NET, Javascript and SQL Server 2000, ASP.NET, Web Service, Window Service)</description><link>http://wec-library.blogspot.com/</link><managingEditor>noreply@blogger.com (Wec)</managingEditor><generator>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-68170180171047125</guid><pubDate>Sun, 28 Sep 2008 05:30:00 +0000</pubDate><atom:updated>2008-09-28T18:34:16.453+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server</category><title>How to Handle Exception and Error in SQL Server 2000 and SQL Server 2005 (Transactions – Rollback Transaction, Commit Transaction)</title><description>SQL Server 2000 doesn’t have a standard and structured way to handle exception in SQL Query. However, we can user the standard error variable &lt;code&gt;&lt;span style=&quot;color:Magenta;&quot;&gt;@@ERROR&lt;/span&gt;&lt;/code&gt; to check whether any error has occurred in order to take the necessary action.&lt;br /&gt;&lt;br /&gt;Example for SQL Server 2000 to handle exception:-&lt;br/&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;BEGIN TRANSACTION&lt;br /&gt;DECLARE&lt;/span&gt; @Err &lt;span style=&quot;color:Blue;&quot;&gt;AS INT&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;-- Put your statements here.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SET&lt;/span&gt; @Err = &lt;span style=&quot;color:Magenta;&quot;&gt;@@ERROR&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;IF&lt;/span&gt; @Err &lt;&gt; 0&lt;br /&gt; &lt;span style=&quot;color:Blue;&quot;&gt;&amp;nbsp;&amp;nbsp;BEGIN&lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ROLLBACK TRANSACTION &lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&lt;/span&gt; &lt;span style=&quot;color:Red;&quot;&gt;&#39;The transaction is rollbacked due to exception or error.&#39;&lt;/span&gt; &lt;span style=&quot;color:Blue;&quot;&gt;AS&lt;/span&gt; RESULT&lt;br /&gt; &lt;span style=&quot;color:Blue;&quot;&gt;&amp;nbsp;&amp;nbsp;END&lt;br /&gt;ELSE&lt;br /&gt; &amp;nbsp;&amp;nbsp;BEGIN&lt;br /&gt;  &amp;nbsp;&amp;nbsp;COMMIT TRANSACTION&lt;br /&gt;  &amp;nbsp;&amp;nbsp;SELECT&lt;/span&gt; &lt;span style=&quot;color:Red;&quot;&gt;&#39;The Transaction is committed.&#39;&lt;/span&gt; &lt;span style=&quot;color:Blue;&quot;&gt;AS&lt;/span&gt; RESULT&lt;br /&gt; &lt;span style=&quot;color:Blue;&quot;&gt;&amp;nbsp;&amp;nbsp;END&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;However, SQL Server 2005 has come with a structured way to handle the exception (Try-Catch blocks). This structure is very similar to those used in C#, VB.Net and Java. &lt;br /&gt;&lt;br /&gt;Example for SQL Server 2005 to handle exception :-&lt;br/&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;BEGIN TRY&lt;br /&gt; &amp;nbsp;&amp;nbsp;BEGIN TRANSACTION&lt;/span&gt;&lt;br /&gt; &lt;span style=&quot;color:#009900;&quot;&gt;&amp;nbsp;&amp;nbsp;-- Put your statements here.&lt;/span&gt;&lt;br /&gt; &lt;span style=&quot;color:Blue;&quot;&gt;&amp;nbsp;&amp;nbsp;COMMIT TRANSACTION&lt;br /&gt; &amp;nbsp;&amp;nbsp;SELECT&lt;/span&gt; &lt;span style=&quot;color:Red;&quot;&gt;&#39;The Transaction is committed.&#39;&lt;/span&gt; &lt;span style=&quot;color:Blue;&quot;&gt;AS&lt;/span&gt; RESULT&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;END TRY&lt;br /&gt;BEGIN CATCH&lt;br /&gt; &amp;nbsp;&amp;nbsp;ROLLBACK TRANSACTION&lt;br /&gt; &amp;nbsp;&amp;nbsp;SELECT&lt;/span&gt; &lt;span style=&quot;color:Red;&quot;&gt;&#39;The transaction is rollbacked due to exception or error.&#39;&lt;/span&gt; &lt;span style=&quot;color:Blue;&quot;&gt;AS&lt;/span&gt; RESULT&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;END CATCH&lt;/span&gt;&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/09/how-to-handle-exception-and-error-in.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-3248062592857539949</guid><pubDate>Sun, 14 Sep 2008 14:09:00 +0000</pubDate><atom:updated>2008-09-14T22:19:44.048+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server</category><title>Query a field size in Database (SQL Server)</title><description>If you want to query the size in bytes for a record or field in database (SQL Server), you can use the &lt;span style=&quot;font-style:italic;&quot;&gt;DATALENGTH&lt;/span&gt; function.&lt;br /&gt;The &lt;span style=&quot;font-style:italic;&quot;&gt;DATALENGTH&lt;/span&gt; function can return the length in bytes for any data types including &lt;span style=&quot;font-style:italic;&quot;&gt;text&lt;/span&gt;, &lt;span style=&quot;font-style:italic;&quot;&gt;ntext&lt;/span&gt;, &lt;span style=&quot;font-style:italic;&quot;&gt;image&lt;/span&gt; and &lt;span style=&quot;font-style:italic;&quot;&gt;varbinary&lt;/span&gt;.&lt;br/&gt;&lt;br /&gt;For example you want to know the size of Field1 in TableA just run the following query:&lt;br/&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; Field1, &lt;span style=&quot;color:Magenta;&quot;&gt;DATALENGTH&lt;/span&gt;(Field1) &lt;span style=&quot;color:Blue;&quot;&gt;AS&lt;/span&gt; [Size Field1 in bytes] &lt;span style=&quot;color:Blue;&quot;&gt;FROM&lt;/span&gt; TableA&lt;/code&gt;&lt;br/&gt;&lt;br /&gt;The output will be the value of Field1 and it&#39;s size in bytes for each rows record in TableA</description><link>http://wec-library.blogspot.com/2008/09/query-field-size-in-database-sql-server.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-5899657947641915855</guid><pubDate>Thu, 24 Apr 2008 07:37:00 +0000</pubDate><atom:updated>2008-04-24T16:54:04.946+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">C#.NET</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Syntax Differences of C# and VB.NET</title><description>Sometimes, I need to convert the codes from C# to VB.NET or from VB.NET to C#. So, I need to know some of the syntax differences of C# and VB.NET. The Table below shows some syntax differences of them:&lt;br /&gt;&lt;br /&gt;&lt;table width=&quot;100%&quot; align=&quot;center&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot;&gt;&lt;tr&gt;&lt;td width=&quot;28%&quot;&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;/td&gt;&lt;td width=&quot;28%&quot;&gt;&lt;strong&gt;VB.NET&lt;/strong&gt;&lt;/td&gt;&lt;td width=&quot;44%&quot;&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;using&lt;/td&gt;&lt;td&gt;Imports&lt;/td&gt;&lt;td&gt;Allows methods to be called without fully qualifying with Namespace name&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;this&lt;/td&gt;&lt;td&gt;Me&lt;/td&gt;&lt;td&gt;Refer to the current object&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;base&lt;/td&gt;&lt;td&gt;MyBase&lt;/td&gt;&lt;td&gt;Refer to the base class&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;static&lt;/td&gt;&lt;td&gt;Shared&lt;/td&gt;&lt;td&gt;Specifies that a member is shared by all instances of a class. To call the member, an instance of the class is not required.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;no equivalent&lt;/td&gt;&lt;td&gt;Static&lt;/td&gt;&lt;td&gt;Specifies that a local variable&#39;s value is preserved between calls.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;not required&lt;/td&gt;&lt;td&gt;ByVal&lt;/td&gt;&lt;td&gt;Passing parameters by value&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ref&lt;/td&gt;&lt;td&gt;ByRef&lt;/td&gt;&lt;td&gt;Passing parameters by reference&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;enum&lt;/td&gt;&lt;td&gt;Enum&lt;/td&gt;&lt;td&gt;Declare an enumerator&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;struct&lt;/td&gt;&lt;td&gt;Structure&lt;/td&gt;&lt;td&gt;Declare a structure&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;obj == null&lt;/td&gt;&lt;td&gt;obj = Nothing&lt;/td&gt;&lt;td&gt;Check whether an object is not ponit to anything&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;on by default and not changable&lt;/td&gt;&lt;td&gt;Option Explicit&lt;/td&gt;&lt;td&gt;Specifies that all variables must be declared.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;delegate&lt;/td&gt;&lt;td&gt;AddressOf&lt;/td&gt;&lt;td&gt;Use the address of a method&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;no equivalent&lt;/td&gt;&lt;td&gt;With&lt;br/&gt;&amp;nbsp;...&lt;br/&gt;End With&lt;/td&gt;&lt;td&gt;Evaluate an object one and use many times.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;int[] x = new int[4] {1,2,3,4};&lt;/td&gt;&lt;td&gt;Dim a() as &lt;/td&gt;&lt;td&gt;Initialise an array.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;lock&lt;/td&gt;&lt;td&gt;SynLock&lt;/td&gt;&lt;td&gt;Threading primitives.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;sealed&lt;/td&gt;&lt;td&gt;NotInheritable&lt;/td&gt;&lt;td&gt;Specifies that a class cannot be used as a base class (cannot be inherited).&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;sealed&lt;/td&gt;&lt;td&gt;NotOverridable&lt;/td&gt;&lt;td&gt;Specifies that a method cannot be overriden.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;abstract&lt;/td&gt;&lt;td&gt;MustInherit&lt;/td&gt;&lt;td&gt;Specifies that a class can only be inherited (an instance of the class cannot be created).&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;abstract&lt;/td&gt;&lt;td&gt;MustOverride&lt;/td&gt;&lt;td&gt;Specifies that a method must be implemented in a derived class.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;virtual&lt;/td&gt;&lt;td&gt;Overridable&lt;/td&gt;&lt;td&gt;Specifies that a member can be overriden&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;override&lt;/td&gt;&lt;td&gt;Overrides&lt;/td&gt;&lt;td&gt;Specifies that a member is overriding another member.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;not required&lt;/td&gt;&lt;td&gt;Overloads&lt;/td&gt;&lt;td&gt;Specifies that a member is overloading another member.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;class Class1:I1&lt;/td&gt;&lt;td&gt;Implements I1&lt;/td&gt;&lt;td&gt;Specifies that the class (Class1) implements the interface I1.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;class Class1:BaseClass1&lt;/td&gt;&lt;td&gt;Inherits BaseClass1&lt;/td&gt;&lt;td&gt;Specifies that the class (Class1) inherits class BaseClass1.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Class1&lt;/td&gt;&lt;td&gt;New&lt;/td&gt;&lt;td&gt;Constructor method, called when object is created. Class1 is classname.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;~Class1&lt;/td&gt;&lt;td&gt;Finalize&lt;/td&gt;&lt;td&gt;Method called by system just before garbage collection reclaims object, known as destrutor method. Class1 is class name.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;hr /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</description><link>http://wec-library.blogspot.com/2008/04/syntax-differences-of-c-and-vbnet.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-1550630255321252276</guid><pubDate>Thu, 17 Apr 2008 15:02:00 +0000</pubDate><atom:updated>2008-04-17T23:18:09.985+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Windows</category><title>Err Msg: “The system cannot log you on to this domain because the system’s machine account in its primary domain is missing or the password...&quot;</title><description>&lt;span style=&quot;font-weight:bold;&quot;&gt;Error Message:&lt;/span&gt; &lt;span style=&quot;font-style:italic;&quot;&gt;“The system cannot log you on to this domain because the system’s machine account in its primary domain is missing or the password on that account is incorrect”&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Today, I need to login my ex-colleague’s PC to setup something at that PC. The PC had not been used anyone for a few months. When I trying to log on to the domain, the error message mentioned in above is displayed. However, I can log into locally. &lt;br /&gt;&lt;br /&gt;I tried to do some configuration setting of the PC but the issue still not been solved. After that, I tried to search with the error message in Google and find the solution to resolve the issue. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Solution:&lt;/span&gt;&lt;br /&gt;If you face this problem, determine whether the PC can be logged into locally. If can, try to perform the following steps to resolve the issue:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Remove the Server from the Domain:&lt;/span&gt;&lt;ol&gt;&lt;li&gt;Click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Start]&lt;/span&gt;, point to &lt;span style=&quot;font-weight:bold;&quot;&gt;[Settings]&lt;/span&gt;, click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Control Panel]&lt;/span&gt;, and double-click &lt;span style=&quot;font-weight:bold;&quot;&gt;[System]&lt;/span&gt;&lt;br /&gt;&lt;li&gt;On the &lt;span style=&quot;font-weight:bold;&quot;&gt;[Network Identification]&lt;/span&gt; tab, click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Properties]&lt;/span&gt;&lt;br /&gt;&lt;li&gt;Under &lt;span style=&quot;font-weight:bold;&quot;&gt;[Member Of]&lt;/span&gt;, click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Workgroup]&lt;/span&gt;, type the name of a workgroup to join, then click &lt;span style=&quot;font-weight:bold;&quot;&gt;[OK]&lt;/span&gt;&lt;br /&gt;&lt;li&gt;Click &lt;span style=&quot;font-weight:bold;&quot;&gt;[OK]&lt;/span&gt; again&lt;br /&gt;&lt;li&gt;Restart the PC&lt;/ol&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Add the Server back to the Domain:&lt;/span&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Start]&lt;/span&gt;, point to &lt;span style=&quot;font-weight:bold;&quot;&gt;[Settings]&lt;/span&gt;, click [Control Panel] then double click &lt;span style=&quot;font-weight:bold;&quot;&gt;[System]&lt;/span&gt;&lt;br /&gt;&lt;li&gt;On the &lt;span style=&quot;font-weight:bold;&quot;&gt;[Network Identification]&lt;/span&gt; tab, click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Properties]&lt;/span&gt;&lt;br /&gt;&lt;li&gt;Under &lt;span style=&quot;font-weight:bold;&quot;&gt;[Member Of]&lt;/span&gt;, click &lt;span style=&quot;font-weight:bold;&quot;&gt;[Domain]&lt;/span&gt;, type the name of a workgroup to join, then click &lt;span style=&quot;font-weight:bold;&quot;&gt;[OK]&lt;/span&gt;&lt;br /&gt;When prompted, provide a user name and password, and join the PC to the domain.&lt;br /&gt;&lt;li&gt;Restart the PC&lt;/ol&gt;Then try to log on the domain, the problem solved.</description><link>http://wec-library.blogspot.com/2008/04/error-message-system-cannot-log-you-on.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-1328019081113199778</guid><pubDate>Sun, 13 Apr 2008 06:37:00 +0000</pubDate><atom:updated>2008-04-13T14:50:13.189+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">ASP .NET 1.1</category><category domain="http://www.blogger.com/atom/ns#">ASP .NET 2.0</category><title>Different between Authorization and Authentication (.NET)</title><description>&lt;span style=&quot;font-weight:bold;&quot;&gt;Authentication&lt;/span&gt; is the mechanism where a system uses to identify their user. In ASP .NET, the authentication may be set in web.config file to verify the credentials of the user and decides whether the user is authenticated or not.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Authorization&lt;/span&gt; is the mechanism where a system uses to determine what level of access for a particular user. &lt;br /&gt;&lt;br /&gt;So, when a user logs on to a system, the user will be authenticated first before be authorized.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Ways to authenticate user in ASP .NET:&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Forms Authentication&lt;/span&gt;&lt;br /&gt;This authentication depends on code written in the system. Credentials are entered on web forms then used to match with the user information in the database table.&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Windows Authentication&lt;/span&gt;&lt;br /&gt;This authentication is the default authentication provider for ASP .NET application. The user logs in to an application using this authentication, the credentials are matched with the Windows domain through IIS.&lt;br /&gt;There are 4 types of Window Authentication methods:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Anonymous Authentication&lt;/span&gt; – IIS allows any user&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Basic Authentication&lt;/span&gt; – windows username and password (credentials) has to be sent across the network in plain text format (not very secure).&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Digest Authentication&lt;/span&gt; – Same as Basic Authentication but the credentials are encrypted.&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Integrated Windows Authentication&lt;/span&gt; – Depend on Kerberos technology, with strong credential encryption.&lt;/ul&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Passport Authentication&lt;/span&gt;&lt;br /&gt;This authentication already obsolete in .NET 2.0&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;“None”&lt;/span&gt; mean no authentication&lt;/ol&gt; &lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Types Authorization in .NET&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;File Authorization&lt;/span&gt;&lt;br /&gt;Relying on the NTFS system for granting permission&lt;br /&gt;&lt;li&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Url Authorization&lt;/span&gt;&lt;br /&gt;Specify authorization rules in web.config for different web URLs.&lt;/ol&gt;</description><link>http://wec-library.blogspot.com/2008/04/different-between-authorization-and.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-7033228191385682372</guid><pubDate>Thu, 20 Mar 2008 09:10:00 +0000</pubDate><atom:updated>2010-07-29T23:00:27.463+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">ASP .NET 1.1</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Calling Javascript Function from Code Behind (.vb)</title><description>This is the function at html page:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:Brown;&quot;&gt;script&lt;/span&gt; &lt;span style=&quot;color:Red;&quot;&gt;language&lt;/span&gt;&lt;span style=&quot;color:Blue;&quot;&gt;=&quot;javascript&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;function&lt;/span&gt; test()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Add the function code here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color:Brown;&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color:Blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To call this javascript function from code behind (.vb), Use &lt;code&gt;&lt;strong&gt;Page.RegisterStartupScript&lt;/strong&gt;&lt;/code&gt; function like the code below:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strScript &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = &quot;&amp;lt;script language=&#39;javascript&#39; id=&#39;myClientScript&#39;&amp;gt;test();&amp;lt;/script&amp;gt;&quot;&lt;br /&gt;Page.RegisterStartupScript(“callTest”,strScript)&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/03/calling-javascript-function-from-code.html</link><author>noreply@blogger.com (Wec)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-1761727502883394412</guid><pubDate>Tue, 18 Mar 2008 06:31:00 +0000</pubDate><atom:updated>2008-03-18T14:35:43.486+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server</category><title>SQL Query Script Used to List out All User Table Name of a Database</title><description>To List out all user table name of a database, just using the query statement as below:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; Table_Name&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.Tables&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;WHERE&lt;/span&gt; Table_Type = &lt;span style=&quot;color:Red;&quot;&gt;&#39;BASE TABLE&#39;&lt;/span&gt;&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/03/sql-query-script-used-to-list-out-all.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-8248070161995080353</guid><pubDate>Tue, 11 Mar 2008 09:23:00 +0000</pubDate><atom:updated>2008-03-11T17:43:56.238+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server</category><title>Ways to Convert Date to Different Formats in SQL Server 2000</title><description>You may want to convert the date into different format that you want. At here, I got example how to convert date to 15 different formats using SQL Query.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YYYYMMDD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 112)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YYYY-MM-DD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(10), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 23)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YYYY-MMM-DD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(10), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 23), 6, 2, LEFT(&lt;span style=&quot;color:Magenta;&quot;&gt;DATENAME&lt;/span&gt;(m, &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;()), 3))&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YYMMDD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;VARCHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 12)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YY-MM-DD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;VARCHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 12), 5, 0, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;), 3, 0, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;YY-MMM-DD&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;VARCHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 12), 3, 2, LEFT(&lt;span style=&quot;color:Magenta;&quot;&gt;DATENAME&lt;/span&gt;(m, &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;()), 3)), 6, 0, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;), 3, 0, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;MM-DD-YY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 10)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;MMDDYY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;REPLACE&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 10), &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;, &lt;span style=&quot;color:Magenta;&quot;&gt;SPACE&lt;/span&gt;(0))&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;MM/DD/YY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 1)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;MM/DD/YYYY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(10), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 101)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;DD-MM-YY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;REPLACE&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 3), &lt;span style=&quot;color:Red;&quot;&gt;&#39;/&#39;&lt;/span&gt;, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;DD-MMM-YY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;STUFF&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;REPLACE&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 3), &lt;span style=&quot;color:Red;&quot;&gt;&#39;/&#39;&lt;/span&gt;, &lt;span style=&quot;color:Red;&quot;&gt;&#39;-&#39;&lt;/span&gt;), 4, 2, LEFT(&lt;span style=&quot;color:Magenta;&quot;&gt;DATENAME&lt;/span&gt;(m, &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;()), 3))&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;DDMMYY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;REPLACE&lt;/span&gt;(&lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 3), &lt;span style=&quot;color:Red;&quot;&gt;&#39;/&#39;&lt;/span&gt;, &lt;span style=&quot;color:Magenta;&quot;&gt;SPACE&lt;/span&gt;(0))&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;DD/MM/YY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(8), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 3)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;--&#39;DD/MM/YYYY&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;SELECT&lt;/span&gt; &lt;span style=&quot;color:Magenta;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color:Blue;&quot;&gt;CHAR&lt;/span&gt;(10), &lt;span style=&quot;color:Magenta;&quot;&gt;GETDATE&lt;/span&gt;(), 103)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Hope that is one the format you want. If not, please write a comment with the format date you want. I will try my best to help you. Thanks.</description><link>http://wec-library.blogspot.com/2008/03/ways-to-convert-date-to-different.html</link><author>noreply@blogger.com (Wec)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-7425443312338271431</guid><pubDate>Mon, 10 Mar 2008 03:39:00 +0000</pubDate><atom:updated>2008-03-10T11:52:56.556+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">ASP .NET 1.1</category><category domain="http://www.blogger.com/atom/ns#">C#.NET</category><title>Gets IP Address of Server PC using C# (ASP .NET 1.1)</title><description>The function below is used to get the IP Address of Server. The &lt;code&gt;&lt;strong&gt;System.Net&lt;/strong&gt;&lt;/code&gt; namespace is needed for this function. This is because &lt;code&gt;&lt;strong&gt;IPHostEntry&lt;/strong&gt;&lt;/code&gt; and &lt;code&gt;&lt;strong&gt;IPAddress&lt;/strong&gt;&lt;/code&gt; are class in &lt;code&gt;&lt;strong&gt;System.Net&lt;/strong&gt;&lt;/code&gt; namespace. Beside this, &lt;code&gt;&lt;strong&gt;GetHostName()&lt;/strong&gt;&lt;/code&gt; function also belong to &lt;code&gt;&lt;strong&gt;System.Net.Dns&lt;/strong&gt;&lt;/code&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;public string&lt;/span&gt; GetIPAddress()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strHostName = System.Net.Dns.GetHostName();&lt;/br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());&lt;/br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;IPAddress ipAddress = ipHostInfo.AddressList[0];&lt;/br&gt;&lt;/br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;return&lt;/span&gt; ipAddress.ToString();&lt;br /&gt;}&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/03/gets-ip-address-of-server-pc-using-c.html</link><author>noreply@blogger.com (Wec)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-7779362329163382488</guid><pubDate>Mon, 25 Feb 2008 07:20:00 +0000</pubDate><atom:updated>2008-02-25T15:48:11.024+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Import Data from Excel File using VB .NET</title><description>The following is the sample code how to query an Excel spreadsheet from an &lt;strong&gt;ASP.NET&lt;/strong&gt; page using &lt;strong&gt;VB .NET&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strConn &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; da &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; OleDbDataAdapter&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; ds &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; New DataSet&lt;br /&gt;&lt;br /&gt;strConn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; &amp; _&lt;br /&gt;          &quot;Data Source=C:\test.xls;Extended Properties=&quot;&quot;Excel 8.0;&quot;&quot;&quot;&lt;br /&gt;da = &lt;span style=&quot;color:Blue;&quot;&gt;New&lt;/span&gt; OleDbDataAdapter(&quot;SELECT * FROM [Sheet1$]&quot;, strConn)&lt;br /&gt;da.TableMappings.Add(&quot;Table&quot;, &quot;Excel&quot;)&lt;br /&gt;da.Fill(ds)&lt;br /&gt;&lt;br /&gt;dataGrid1.DataSource = ds.Tables(0).DefaultView&lt;br /&gt;dataGrid1.DataBind()&lt;br /&gt;da.Dispose()&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;The code above is just select data from Sheet1 (Worksheet) only.&lt;/ul&gt;If you want to select data from first sheet in the Excel workbook, you need to know the name of the first sheet first.&lt;br /&gt;To get the name of the first sheet in the Excel workbook, refer code below:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; dao_dbE &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; dao.DBEngine&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; dao_DB &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; DAO.Database&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFirstSheetName &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;dao_dbE = &lt;span style=&quot;color:Blue;&quot;&gt;New&lt;/span&gt; dao.DBEngine&lt;br /&gt;dao_DB = dao_dbE.OpenDatabase(&quot;C:\test.xls&quot;, &lt;span style=&quot;color:Blue;&quot;&gt;False&lt;/span&gt;, &lt;span style=&quot;color:Blue;&quot;&gt;True&lt;/span&gt;, &quot;Excel 8.0;&quot;)&lt;br /&gt;strFirstSheetName = dao_DB.TableDefs(0).Name&lt;br /&gt;da0_DB.Close()&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;Microsoft DAO 3.5 Library needs to add to the project when source code above is used. From the Project menu, click References, click Add Reference… and then select the Microsoft DAO 3.5 Library to add.&lt;/ul&gt;So, complete source code should be like this:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strConn &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; da &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; OleDbDataAdapter&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; ds &lt;span style=&quot;color:Blue;&quot;&gt;As New&lt;/span&gt; DataSet&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; dao_dbE &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; dao.DBEngine&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; dao_DB &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; DAO.Database&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFirstSheetName &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;dao_dbE = &lt;span style=&quot;color:Blue;&quot;&gt;New&lt;/span&gt; dao.DBEngine&lt;br /&gt;dao_DB = dao_dbE.OpenDatabase(&quot;C:\test.xls&quot;, &lt;span style=&quot;color:Blue;&quot;&gt;False&lt;/span&gt;, &lt;span style=&quot;color:Blue;&quot;&gt;True&lt;/span&gt;, &quot;Excel 8.0;&quot;)&lt;br /&gt;strFirstSheetName = dao_DB.TableDefs(0).Name&lt;br /&gt;strConn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; &amp; _&lt;br /&gt;          &quot;Data Source=C:\test.xls;Extended Properties=&quot;&quot;Excel 8.0;&quot;&quot;&quot;&lt;br /&gt;&lt;br /&gt;da = &lt;span style=&quot;color:Blue;&quot;&gt;New&lt;/span&gt; OleDbDataAdapter(&quot;SELECT * FROM [&quot; &amp; _&lt;br /&gt;     strFirstSheetName &amp; &quot;]&quot;, strConn)&lt;br /&gt;da.TableMappings.Add(&quot;Table&quot;, &quot;Excel&quot;)&lt;br /&gt;da.Fill(ds)&lt;br /&gt;&lt;br /&gt;dataGrid1.DataSource = ds.Tables(0).DefaultView&lt;br /&gt;dataGrid1.DataBind()&lt;br /&gt;&lt;br /&gt;da.Dispose()&lt;br /&gt;da0_DB.Close()</description><link>http://wec-library.blogspot.com/2008/02/import-data-from-excel-file-using-vb.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-6881815880986364555</guid><pubDate>Thu, 21 Feb 2008 07:40:00 +0000</pubDate><atom:updated>2008-02-21T15:47:39.672+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">MS Excel</category><title>Highlight Lottery Numbers (TOTO) using Microsoft Excel</title><description>Let me show you an example how to highlight the ticket numbers that have been drawn in a lottery.  Let said you have 5 ticket numbers that are in cells B4:G8 and the drawn numbers are entered in cells B2:G2.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Select cells B4:G8.&lt;br /&gt;&lt;li&gt;Choose [Format] &gt; [Conditional Formatting].&lt;br /&gt;&lt;li&gt;From the first dropdown list, choose &lt;strong&gt;&lt;em&gt;Formula Is&lt;/em&gt;&lt;/strong&gt;.&lt;br /&gt;&lt;li&gt;For the formula, use the CountIf function: &lt;strong&gt;&lt;em&gt;=COUNTIF($B$2:$G$6,B4)&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;li&gt;Click the [Format] button.&lt;br /&gt;&lt;li&gt;Select formatting options (green pattern, in this example), then click [OK] button.&lt;br /&gt;&lt;li&gt;Finally, click [OK] button.&lt;/ol&gt;&lt;br /&gt;Wish you have a lucky day!</description><link>http://wec-library.blogspot.com/2008/02/highlight-lottery-numbers-toto-using.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-7540439656011804399</guid><pubDate>Wed, 20 Feb 2008 09:52:00 +0000</pubDate><atom:updated>2008-09-19T15:10:04.358+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HTML</category><title>How to link to location on the same page using HTML</title><description>How to create a links that can jump into specific section on a page? We can do it by using the Anchor Tag and the Name Attribute. That is simple and direct.&lt;br /&gt;Below is the syntax:&lt;br /&gt;&lt;code&gt;&amp;lt;a name=”name_of_section”&amp;gt;Text to be displayed&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;a href=#name_of_section”&amp;gt;Text to be displayed&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For Example:&lt;br /&gt;I put the line below at the top of this post&lt;br /&gt;&amp;lt;a name=”top”&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;To go back to the top of this post, I use the following line:&lt;br /&gt;&amp;lt;a href=#top&amp;gt;Go to top of this post&amp;lt;/a&amp;gt;&lt;br /&gt;&lt;a href=#top&gt;Go to top of this post&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can also link to a particular section on another page directly too; just add a # sign and the name of the anchor to the end of a URL. For Example, to link directly to section 2 (“w2”) of my previous post (with title “ASP .NET Web Service: “The request failed with HTTP status 401: Access Denied.”  Error”), I use like this:&lt;br /&gt;&lt;code&gt;&amp;lt;a href=&quot;http://wec-library.blogspot.com/2008/02/asp-net-web-service-request-failed-with.html#w2”&amp;gt;Section 2 of Previous Post&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;a href=http://wec-library.blogspot.com/2008/02/asp-net-web-service-request-failed-with.html#w2&gt;Section 2 of Previous Post&lt;/a&gt;</description><link>http://wec-library.blogspot.com/2008/02/how-to-link-to-location-on-same-page.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-7741691936122023534</guid><pubDate>Thu, 14 Feb 2008 08:32:00 +0000</pubDate><atom:updated>2008-02-14T16:49:55.256+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">C#.NET</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>ASP .NET Web Service: “The request failed with HTTP status 401: Access Denied.”  Error</title><description>You may face this error when trying to access a Web Service from your ASP.NET Application. This is because the Anonymous access authentication for the Web Service is turned off. I also was facing this error before. However, I found out 2 ways to resolve this error, there are:&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;#w1&quot;&gt;1. Enable Anonymous Access in the IIS Directory Security&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;#w2&quot;&gt;2. Assign the Credential Cache Programmatically&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name=&quot;w1&quot;&gt;&lt;/a&gt;&lt;u&gt;&lt;strong&gt;1. Enable Anonymous Access in the IIS Directory Security&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;To do this, try the following steps:&lt;ol&gt;&lt;li&gt;Click [Start] -&gt; [Run] -&gt; Type “inetmgr” and press [OK] or [Enter] key to open IIS Control panel.&lt;br /&gt;&lt;li&gt;Expand the appropriate nodes and navigate to the virtual directory of your Web Service Application.&lt;br /&gt;&lt;li&gt;Select the Virtual Directory, right click and select [Properties].&lt;br /&gt;&lt;li&gt;Click to [Directory Security] Tab and then click [Edit] button.&lt;br /&gt;&lt;li&gt;Check the [Anonymous access] check box.&lt;br /&gt;&lt;li&gt;Click [OK] twice to exit.&lt;/ol&gt;&lt;br /&gt;&lt;a name=&quot;w2&quot;&gt;&lt;/a&gt;&lt;u&gt;&lt;strong&gt;2. Assign the Credential Cache Programmatically&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;You also can programmatically to allow the permissions by specifying the credential cache.&lt;br /&gt;&lt;br /&gt;Let say WS is the object of your Web Service (WebService1 which has the default Method HelloWorld.)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;br /&gt;&lt;code&gt;WebService1 WS = &lt;span style=&quot;color:Blue;&quot;&gt;new&lt;/span&gt; WebService1();&lt;br /&gt;WS.Credentials = System.Net.CredentialCache.DefaultCredentials;&lt;br /&gt;Response.Write(WS.HelloWorld());&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; WS &lt;span style=&quot;color:Blue;&quot;&gt;As New&lt;/span&gt; WebService1&lt;br /&gt;WS.Credentials = System.Net.CredentialCache.DefaultCredentials&lt;br /&gt;Response.Write(WS.HelloWorld())&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/02/asp-net-web-service-request-failed-with.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-6287709859743517381</guid><pubDate>Mon, 28 Jan 2008 02:07:00 +0000</pubDate><atom:updated>2008-01-28T10:59:26.006+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">C#.NET</category><title>Export Data to Excel File not in HTML Table Format using C#.NET</title><description>If you would like to see how to export data to Excel file not in HTML table using &lt;strong&gt;VB.NET&lt;/strong&gt;, &lt;a href=&quot;http://wec-library.blogspot.com/2008/01/export-data-to-excel-file-not-in-html.html&quot;&gt;click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There are a few ways to export data to Excel file, either in HTML Table or in Excel’s original table. Previously, I use the method that export data to Excel file in HTML Table (with extension .xls). However, I faced with troubles when I want to re-import the Excel File using &lt;code&gt;System.Data.OleDb&lt;/code&gt; method (&lt;code&gt;OleDbConnection&lt;/code&gt;, &lt;code&gt;OleDbDataAdapter&lt;/code&gt;, etc).&lt;br /&gt;&lt;br /&gt;Firstly, I set the connection string like below:&lt;br /&gt;&lt;code&gt;strConn = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source= “ + strFilePath + “; Extended Properties=Excel 8.0;”&lt;/code&gt;&lt;br /&gt;With this totally cannot import Excel file in HTML Table.&lt;br /&gt;&lt;br /&gt;Secondly, I tried to change the Extended Properties=HTML Import, the connection string is like below:&lt;br /&gt;&lt;code&gt;strConn = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source= “ + strFilePath + “; Extended Properties=HTML Import;”&lt;/code&gt;&lt;br /&gt;With this, the Excel file in HTML Table can be imported. However, when I add in new row record manually to that file, save it and re-import it; the new row record I manually added is not be selected. This is because this method only will select the records in HTML Table but the new record I added is not in HTML Table (is in Excel’s original table).&lt;br /&gt;&lt;br /&gt;Therefore, what I can do to solve this problem is to change the method I export data to Excel file. I need to find another way to export data to Excel file that not in HTML Table. I had searched around internet and finally I had found the way to export data into the actual Excel table format that using &lt;code&gt;Exel.ApplicationClass&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Firstly, you need to add a component known as &lt;strong&gt;Excel.dll&lt;/strong&gt; (&lt;strong&gt;Microsoft excel 11.0 Object Library&lt;/strong&gt;) into your .NET project references. The codes of the function to export data to Excel file is like below:-&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;private void&lt;/span&gt; ExportToExcelFile(System.Data.DataTable dt)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Application xlsApp = &lt;span style=&quot;color:Blue;&quot;&gt;new&lt;/span&gt; Excel.ApplicationClass();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Workbook xlsWorkbook;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Worksheet xlsWorksheet;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strhdr;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;int&lt;/span&gt; row;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strFile = &quot;file1.xls&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; filename = Server.MapPath(strFile);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;if&lt;/span&gt; (dt.Rows.Count &gt; 0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Create new workbook&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorkbook = xlsApp.Workbooks.Add(&lt;span style=&quot;color:Blue;&quot;&gt;true&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Get the first worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet = (Excel.Worksheet)(xlsWorkbook.Worksheets[1]);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Activate current worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Activate();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Set header row to row 1&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row = 1;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Add table headers to worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 1] = &quot;Name&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 2] = &quot;Gender&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 3] = &quot;Age&quot;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Format header row (bold, extra row height, autofit width)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A&quot; + row.ToString(), &quot;C&quot; + row.ToString()).Font.Bold = &lt;span style=&quot;color:Blue;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A&quot; + row.ToString(), &quot;C&quot; + row.ToString()).Rows.RowHeight = 1.5 * xlsWorksheet.StandardHeight;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A&quot; + row.ToString(), &quot;C&quot; + row.ToString()).EntireRow.AutoFit();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Freeze the columm headers&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A&quot; + (row + 1).ToString(), &quot;C&quot; + (row + 1).ToString()).Select();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsApp.ActiveWindow.FreezePanes = &lt;span style=&quot;color:#009900;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Write data to Excel worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;foreach&lt;/span&gt; (DataRow dr &lt;span style=&quot;color:Blue;&quot;&gt;in&lt;/span&gt; dt.Rows)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row += 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;if&lt;/span&gt; (dr[&quot;Name&quot;] != &lt;span style=&quot;color:Blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 1] = dr[&quot;Name&quot;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;if&lt;/span&gt; (dr[&quot;Gender&quot;] != &lt;span style=&quot;color:Blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 2] = dr[&quot;Gender&quot;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;if&lt;/span&gt; (dr[&quot;Age&quot;] != &lt;span style=&quot;color:Blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells[row, 3] = dr[&quot;Age&quot;];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Format data rows (align to center and left, autofit width and height)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A2&quot;, &quot;C&quot; + row.ToString()).VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A2&quot;, &quot;C&quot; + row.ToString()).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A2&quot;, &quot;c&quot; + row.ToString()).EntireColumn.AutoFit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.get_Range(&quot;A2&quot;, &quot;c&quot; + row.ToString()).EntireRow.AutoFit();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Make excel workbook visible to user after all data has been added to worksheet.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsApp.DisplayAlerts = &lt;span style=&quot;color:Blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorkbook.Close(&lt;span style=&quot;color:Blue;&quot;&gt;true&lt;/span&gt;, filename, &lt;span style=&quot;color:Blue;&quot;&gt;null&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;//Export data to client machine&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;strhdr = &quot;attachment;filename=&quot; + strFile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Clear();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.ContentType = &quot;application/vnd.ms-excel&quot;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.ContentEncoding = System.Text.Encoding.Default;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.AppendHeader(&quot;Content-Disposition&quot;,strhdr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.WriteFile(filename);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Flush();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Clear();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/01/export-data-to-excel-file-not-in-html_28.html</link><author>noreply@blogger.com (Wec)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-2163049970298059309</guid><pubDate>Mon, 28 Jan 2008 01:06:00 +0000</pubDate><atom:updated>2008-01-28T10:58:37.274+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Export Data to Excel File not in HTML Table Format using VB.NET</title><description>If you would like to see how to export data to Excel file not in HTML table using C#, &lt;a href=&quot;http://wec-library.blogspot.com/2008/01/export-data-to-excel-file-not-in-html_28.html&quot;&gt;click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;There are a few ways to export data to Excel file, either in HTML Table or in Excel’s original table. Previously, I use the method that export data to Excel file in HTML Table (with extension .xls). However, I faced with troubles when I want to re-import the Excel File using &lt;code&gt;System.Data.OleDb&lt;/code&gt; method (&lt;code&gt;OleDbConnection&lt;/code&gt;, &lt;code&gt;OleDbDataAdapter&lt;/code&gt;, etc).&lt;br /&gt;&lt;br /&gt;Firstly, I set the connection string like below:&lt;br /&gt;&lt;code&gt;strConn = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source= “ &amp; strFilePath &amp; “; Extended Properties=Excel 8.0;”&lt;/code&gt;&lt;br /&gt;With this totally cannot import Excel file in HTML Table.&lt;br /&gt;&lt;br /&gt;Secondly, I tried to change the Extended Properties=HTML Import, the connection string is like below:&lt;br /&gt;&lt;code&gt;strConn = “Provider=Microsoft.Jet.OLEDB.4.0; Data Source= “ &amp; strFilePath &amp; “; Extended Properties=HTML Import;”&lt;/code&gt;&lt;br /&gt;With this, the Excel file in HTML Table can be imported. However, when I add in new row record manually to that file, save it and re-import it; the new row record I manually added is not be selected. This is because this method only will select the records in HTML Table but the new record I added is not in HTML Table (is in Excel’s original table).&lt;br /&gt;&lt;br /&gt;Therefore, what I can do to solve this problem is to change the method I export data to Excel file. I need to find another way to export data to Excel file that not in HTML Table. I had searched around internet and finally I had found the way to export data into the actual Excel table format that using &lt;code&gt;Exel.Application&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Firstly, you need to add a component known as &lt;strong&gt;Excel.dll&lt;/strong&gt; (&lt;strong&gt;Microsoft excel 11.0 Object Library&lt;/strong&gt;) into your .NET project references. The codes of the function to export data to Excel file is like below:-&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Private Funtion&lt;/span&gt; ExportToExcelFile(&lt;span style=&quot;color:Blue;&quot;&gt;ByVal&lt;/span&gt; dt &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; System.Data.DataTable)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; xlsApp &lt;span style=&quot;color:Blue;&quot;&gt;As New&lt;/span&gt; Excel.Application&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; xlsWorkbook &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; Excel.Workbook&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; xlsWorksheet &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; Excel.Worksheet&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strhdr &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; row &lt;span style=&quot;color:Blue;&quot;&gt;As Integer&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; dr &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; DataRow&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFile &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = &quot;file1.xls&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; filename &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(strFile)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;If&lt;/span&gt; dt.Rows.Count &gt; 0 &lt;span style=&quot;color:Blue;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Create new workbook&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorkbook = xlsApp.Workbooks.Add&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Get the first worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet = &lt;span style=&quot;color:Blue;&quot;&gt;CType&lt;/span&gt;(xlsWorkbook.Worksheets(1), Excel.Worksheet)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Activate current worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Activate()&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Set header row to row 1&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row = 1&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Add table headers to worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells(row, 1).Value = &quot;Name&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells(row, 2).Value = &quot;Gender&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorksheet.Cells(row, 3).Value = &quot;Age&quot;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Format header row (bold, extra row height, autofit width)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;With&lt;/span&gt; xlsWorksheet.Range(&quot;A&quot; &amp; row, &quot;C&quot; &amp; row)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Font.Bold = &lt;span style=&quot;color:Blue;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Rows(row).RowHeight = 1.5 * xlsWorksheet.StandardHeight&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.EntireRow.AutoFit()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;End With&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Freeze the column headers&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;With&lt;/span&gt; xlsWorksheet.Range(&quot;A&quot; &amp; row + 1, &quot;C&quot; &amp; row + 1).Select&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsApp.ActiveWindow.FreezePanes = &lt;span style=&quot;color:Blue;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;End With&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Write data to Excel worksheet&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;For Each&lt;/span&gt; dr &lt;span style=&quot;color:Blue;&quot;&gt;In&lt;/span&gt; dt.Rows&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row += 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If Not IsDBNull(dr.Item(&quot;Name&quot;)) Then xlsWorksheet.Cells(row, 1).Value = dr.Item(&quot;Name&quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If Not IsDBNull(dr.Item(&quot;Gender &quot;)) Then xlsWorksheet.Cells(row, 2).Value = dr.Item(&quot;Gender&quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If Not IsDBNull(dr.Item(&quot;Age&quot;)) Then xlsWorksheet.Cells(row, 3).Value = dr.Item(&quot;Age&quot;)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Format data rows (align to center and left, autofit width and height)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;With&lt;/span&gt; xlsWorksheet.Range(&quot;A2&quot;, &quot;C&quot; &amp; row)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.VerticalAlignment = &lt;span style=&quot;color:Blue;&quot;&gt;CType&lt;/span&gt;(XlVAlign.xlVAlignCenter, Excel.XlVAlign)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.HorizontalAlignment = &lt;span style=&quot;color:Blue;&quot;&gt;CType&lt;/span&gt;(XlHAlign.xlHAlignLeft, Excel.XlHAlign)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.EntireColumn.AutoFit()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.EntireRow.AutoFit()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;End With&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Make excel workbook visible to user after all data has been added to worksheet.&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsApp.DisplayAlerts = &lt;span style=&quot;color:Blue;&quot;&gt;False&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xlsWorkbook.Close(&lt;span style=&quot;color:Blue;&quot;&gt;True&lt;/span&gt;, filename)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;Export data to client machine&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;strhdr = &quot;attachment;filename=&quot; &amp; strFile&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;With&lt;/span&gt; Response&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Clear()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ContentType = &quot;application/vnd.ms-excel&quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ContentEncoding = System.Text.Encoding.Default&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.AppendHeader(&quot;Content-Disposition&quot;, strhdr)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.WriteFile(filename)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Flush()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Clear()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Close()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;End With&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color:Blue;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;End Function&lt;/span&gt;&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/01/export-data-to-excel-file-not-in-html.html</link><author>noreply@blogger.com (Wec)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-6540047489070639209</guid><pubDate>Wed, 23 Jan 2008 07:17:00 +0000</pubDate><atom:updated>2008-01-23T17:05:19.164+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><title>.NET Web Service error - &quot;The test form is only available for requests from the local machine&quot;</title><description>I faced this error before and I already solved it.&lt;br /&gt;&lt;br /&gt;I had created a window service application that will call web service functions that located at my local PC. The application is working as what I did and required. However, after I has migrated the web service application to Server (or different PC) and I changed my window service application to call the web service functions at Server, the application cannot work. &lt;br /&gt;&lt;br /&gt;Then, I tried to browse to the web service at Server using Internet Browser, when I click the function, it showed the message – “The test form is only available for requests from the local machine”.&lt;br /&gt;&lt;br /&gt;After that, I found the solution to solve it. I just added in some code into the Web.config for the Web Service application. The code is like below:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;configuration&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;system.web&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;webServices&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;protocols&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add name=&quot;HttpGet&quot;/&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;add name=&quot;HttpPost&quot;/&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/protocols&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/webServices&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&gt;&lt;br /&gt;&amp;lt;/configuration&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Cheer! Happy Programming!</description><link>http://wec-library.blogspot.com/2008/01/net-web-service-error-test-form-is-only.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-3097315644527590009</guid><pubDate>Mon, 21 Jan 2008 01:58:00 +0000</pubDate><atom:updated>2008-02-14T16:52:05.079+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Window Service timer problem - VB.NET</title><description>&lt;div&gt;I had written a Windows Service application in VB.NET before and I faced a problem. I used timer to do the schedule task in this application. I dropped a Timer Control on the designer then add the Tick event to do the schedule task. I can built, install, stop and restart the service. However, the problem is it the Tick event never fires at all.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;After that, I try to use code to create the timer. I changed to use &lt;code&gt;System.Timers.Timer&lt;/code&gt; instead of &lt;code&gt;System.Windows.Forms.Timer&lt;/code&gt; dropped on the designer from Toolbox. Then it is work already. The code is like below:&lt;/div&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; timerSchedule &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; System.Timers.Timer&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Protected Overrides Sub&lt;/span&gt; OnStart(&lt;span style=&quot;color:Blue;&quot;&gt;ByVal&lt;/span&gt; args() &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;)&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;timerSchedule = &lt;span style=&quot;color:Blue;&quot;&gt;New&lt;/span&gt; System.Timers.Timer(1000)&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;AddHandler&lt;/span&gt; timerSchedule.Elapsed, &lt;span style=&quot;color:Blue;&quot;&gt;AddressOf&lt;/span&gt; timerSchedule_Elapsed&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;timerSchedule.Start()&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;End Sub&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Private Sub&lt;/span&gt; timerSchedule_Elapsed(&lt;span style=&quot;color:Blue;&quot;&gt;ByVal&lt;/span&gt; pSender &lt;span style=&quot;color:Blue;&quot;&gt;As Object&lt;/span&gt;, &lt;span style=&quot;color:Blue;&quot;&gt;ByVal&lt;/span&gt; pArgs &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; System.Timers.ElapsedEventArgs)&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Try&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;timerSchedule.Stop()&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;call my a function to do the scheduled task&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;DoScheduledTask()&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Catch&lt;/span&gt; ex &lt;span style=&quot;color:Blue;&quot;&gt;As&lt;/span&gt; Exception&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Finally&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;timerSchedule.Start()&lt;/code&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;End Try&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;End Sub&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Try to know more about &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.timers.aspx&quot;&gt;System.Timers Namespace&lt;/a&gt;, it will help you more.</description><link>http://wec-library.blogspot.com/2008/01/window-service-timer-problem-vbnet.html</link><author>noreply@blogger.com (Wec)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-1995962650735682043</guid><pubDate>Fri, 11 Jan 2008 07:17:00 +0000</pubDate><atom:updated>2008-02-14T16:52:30.211+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET Programming</category><category domain="http://www.blogger.com/atom/ns#">C#.NET</category><category domain="http://www.blogger.com/atom/ns#">VB.NET</category><title>Server.MapPath Method</title><description>&lt;strong&gt;Server.MapPath&lt;/strong&gt; is a function that takes one argument, a virtual path on the Web server, and returns the corresponding physical path.&lt;br /&gt;&lt;br /&gt;This function can be used in a number of ways.&lt;br /&gt;First, you can use it to obtain the physical path of a particular web page. For example:&lt;br /&gt;&lt;code&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strFilePath;&lt;br /&gt;strFilePath = Server.MapPath(&quot;/WebApp/myWebPage.aspx&quot;);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFilePath &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt;&lt;br /&gt;strFilePath = Server.MapPath(&quot;/WebApp/myWebPage.aspx&quot;)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The output would depend on the web site&#39;s physical root directory, but it might be something like: &quot;C:\Inetpub\wwwroot\WebApp\myWebpage.aspx&quot;.&lt;br /&gt;&lt;br /&gt;You also can use this method to obtain the physical path of a particular directory. For example:&lt;br /&gt;&lt;code&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;//current directory&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strCurrDir = Server.MapPath(&quot;&quot;);&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;//parent directory&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strParentDir = Server.MapPath(&quot;..&quot;);&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;//root directory&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strRootDir = Server.MapPath(&quot;/&quot;);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;current directory&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strCurrDir &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(&quot;&quot;)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;parent directory&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strParentDir &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(&quot;..&quot;)&lt;br /&gt;&lt;span style=&quot;color:#009900;&quot;&gt;&#39;root directory&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strRootDir &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(&quot;/&quot;)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Whether you use backslahed (\) or forward slashes (/), it is same in this function. If you do not put a forward or backward slash at the beginning of the string passed into &lt;code&gt;Server.MapPath&lt;/code&gt;, the current directory that the ASP page is being executed is used as the base for the physical path. Else, the root physical path is used as the base for the physical path. For example:&lt;br /&gt;&lt;code&gt;&lt;strong&gt;C#&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strFilePath1 = Server.MapPath(&quot;someXmlFile.xml&quot;);&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;string&lt;/span&gt; strFilePath2 = Server.MapPath(&quot;/someXmlFile.xml&quot;);&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Visual Basic&lt;/strong&gt;&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFilePath1 &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(&quot;someXmlFile.xml&quot;)&lt;br /&gt;&lt;span style=&quot;color:Blue;&quot;&gt;Dim&lt;/span&gt; strFilePath2 &lt;span style=&quot;color:Blue;&quot;&gt;As String&lt;/span&gt; = Server.MapPath(&quot;/someXmlFile.xml&quot;)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The two lines code above is executed in a ASP page running in the /Dir directory, where the page had physical path C:\Inetpub\wwwroot\Dir. So, the value of strFilePath1 and strFilePath2 will not be the same, where the value of strFilePath1 is C:\Inetpub\wwwroot\Dir\someXmlFile.xml and the value of strFilePath2 is C:\Inetpub\wwwroot\someXmlFile.xml.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br /&gt;To use MapPath function in a code-behind module, use &lt;code&gt;HttpContext.Current.Server.MapPath&lt;/code&gt;.</description><link>http://wec-library.blogspot.com/2008/01/servermappath-method.html</link><author>noreply@blogger.com (Wec)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4234856802821028105.post-9118530281397359651</guid><pubDate>Fri, 11 Jan 2008 01:02:00 +0000</pubDate><atom:updated>2008-10-30T14:00:28.856+08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Server</category><title>SQL Server function for datetime - DATEADD</title><description>DATEADD is a date function will return a datetime value based on the number interval add to the particular date part of the specified date. The syntax DATEADD is like:&lt;br /&gt;&lt;code&gt;DATEADD(date_part, number_interval, specified_date)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;date_part is the parameter that specifies on which part of the date to be manipulated with the number interval. You can add month, year, day and etc. You can use &lt;code&gt;&lt;br /&gt;MONTH, MM or M for month&lt;br /&gt;YEAR, YYYY, YY for year&lt;br /&gt;DAY, DD, D for day&lt;br /&gt;HH for hour&lt;br /&gt;SS, S for Second&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For example : &lt;code&gt;&lt;br /&gt;SELECT DATEADD(D, -1, GETDATE())AS [Yesterday]&lt;br /&gt;SELECT DATEADD(MM, 3, GETDATE())AS [ThreeMonthsFromNow]&lt;br /&gt;SELECT DATEADD(YEAR, -2, GETDATE())AS [TwoYearsAgo]&lt;/code&gt;</description><link>http://wec-library.blogspot.com/2008/01/dateadd-is-date-function-will-return.html</link><author>noreply@blogger.com (Wec)</author><thr:total>0</thr:total></item></channel></rss>