<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by TLF on Medium]]></title>
        <description><![CDATA[Stories by TLF on Medium]]></description>
        <link>https://medium.com/@tklofb?source=rss-51a023198bc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*MeM_JgLJC6TUby8EmJWEwQ.png</url>
            <title>Stories by TLF on Medium</title>
            <link>https://medium.com/@tklofb?source=rss-51a023198bc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:57:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tklofb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SQL Server (T-SQL): How to filter with “IN” like but with multiple properties list data.]]></title>
            <link>https://tklofb.medium.com/sql-server-t-sql-how-to-filter-with-in-like-but-with-multiple-properties-list-data-82d2aabdfaa5?source=rss-51a023198bc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/82d2aabdfaa5</guid>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[t-sql]]></category>
            <dc:creator><![CDATA[TLF]]></dc:creator>
            <pubDate>Sat, 11 Mar 2023 05:36:44 GMT</pubDate>
            <atom:updated>2023-03-11T05:36:44.021Z</atom:updated>
            <content:encoded><![CDATA[<p>When we have a list of data and we want to use it for filtering, we can just use “IN” keywords for it.</p><p>For examples, with this datasource</p><p>(I’m going to use sample Northwind database for this article. <a href="https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/downloading-sample-databases">https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/downloading-sample-databases</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*4vjj9wj79SEbqIlLG-lg0w.png" /></figure><p>We can use IN keyword like this for filtering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*3nyAcGGF6yPDF-eE9HyLhQ.png" /></figure><p>But sometimes when we have one list of data with multiple keys and we want to use it to filter data <strong>“IN”</strong> keyword won’t be your answer anymore.</p><p>For example, If you want to list employees who sastify this conditions</p><ol><li>Sales Representative who are “Ms.”</li><li>Sales Manager who are “Mr.’</li></ol><p>If you try to use <strong>“IN”</strong> keyword like this, You would get wrong result as you can see in the picture that “Sales Representative” who are “Mr.” is also show up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*A1U1NNrX7OaO0_mvfcCIdQ.png" /></figure><p>So, Today we are going to find out how can we do this in T-SQL</p><p><strong>1st Method</strong></p><p>We can just simply use “AND” together with “OR” to solve this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*eEkT_EShxYORtStRmptVyg.png" /></figure><p><strong>2nd Method</strong></p><p>Use temp table with “EXISTS”. (By the way, we can change temp table to common table expression instead.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*IPG4_OjC3wp9RZrsZ5vnKQ.png" /></figure><p><strong>3rd Method</strong></p><p>Concat two keys with some separator that surely not exists in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*bS_hXqONdB_AUnPe7lyK8A.png" /></figure><p>By the way, we didn’t talk about the performance of the query here so please be careful when you’re going to use it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82d2aabdfaa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What should I use to checking empty or null string.]]></title>
            <link>https://tklofb.medium.com/what-should-i-use-to-checking-empty-or-null-string-3c0a6310e64b?source=rss-51a023198bc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c0a6310e64b</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[benchmarking]]></category>
            <dc:creator><![CDATA[TLF]]></dc:creator>
            <pubDate>Sat, 11 Feb 2023 02:39:48 GMT</pubDate>
            <atom:updated>2023-02-11T02:39:48.661Z</atom:updated>
            <content:encoded><![CDATA[<p>When we write the code in C#, we have many ways to check the if the string has the value or not (if we don’t want the whitespace).</p><p>For example, Following expressions has similar result.</p><ol><li>text != null &amp;&amp; text.Trim() != string.Empty</li><li>text?.Trim() != string.Empty</li><li>string.IsNullOrEmpty(text?.Trim())</li><li>string.IsNullOrWhiteSpace(text)</li></ol><p>At the first glance at these expressions, I think we can say that the 4th expression string.IsNullOrWhiteSpace is the best for readability.</p><p>Today we are going to do simple test to check that are there any different on performance wise for these expressions.</p><p>I’m going to use <a href="https://github.com/dotnet/BenchmarkDotNet">https://github.com/dotnet/BenchmarkDotNet</a> for this article.</p><h3><strong>Source code for bench marking</strong></h3><pre>using BenchmarkDotNet.Attributes;<br>using BenchmarkDotNet.Jobs;<br>using BenchmarkDotNet.Running;<br>using System;<br><br>namespace EmptyChecking<br>{<br>    class Program<br>    {<br>        static void Main(string[] args)<br>        {<br>            var summary = BenchmarkRunner.Run&lt;StringChecker&gt;();<br>        }<br>    }<br><br>    public class StringChecker<br>    {<br>        private const string MyString = @&quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit, <br>                                            sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, <br>                                            quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor <br>                                            in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat <br>                                            non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&quot;;<br><br>        [Benchmark]<br>        public bool ManualCheck() =&gt; (MyString != null &amp;&amp; MyString.Trim() != string.Empty);<br><br>        [Benchmark]<br>        public bool ManualCheckWithNullableExpression() =&gt; (MyString?.Trim() != string.Empty);<br><br>        [Benchmark]<br>        public bool IsNullOrEmpty() =&gt; (MyString != null &amp;&amp; string.IsNullOrEmpty(MyString));<br><br>        [Benchmark]<br>        public bool IsNullOrWhiteSpace() =&gt; string.IsNullOrWhiteSpace(MyString);<br>    }<br>}</pre><h3><strong>Let’s see the result</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*kRwhu-7Wy3C2HUEFwaa5kw.png" /></figure><p>We can say that<em> </em><strong><em>string.IsNullOrEmpty(text?.Trim())</em> </strong>is the best for checking and ten times faster than <strong><em>string.IsNullOrWhiteSpace(text).</em></strong></p><p>if our application is <strong>very super sensitive</strong> to performance, I think it’s the best to just use <strong><em>IsNullOrEmpty</em></strong> but in the end it’s just a <strong>nano seconds</strong> so in the most of application I don’t think it’s make that much different.</p><p><strong>P.S.</strong></p><p>By the way, Is <strong><em>string.IsNullOrEmpty(text?.Trim()) </em></strong>and<strong><em> string.IsNullOrWhiteSpace(text) </em></strong>are identical?</p><p>If we take a look at the implementation of Trim() we can see that it also use Char.IsWhiteSpace to check the whitespace which is the same as how <strong><em>IsNullOrWhiteSpace() </em></strong>check the whitespace.</p><p><a href="https://github.com/microsoft/referencesource/blob/master/mscorlib/system/string.cs">referencesource/string.cs at master · microsoft/referencesource</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c0a6310e64b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[การสร้างลิสท์ด้วยใช้ข้อมูลจาก REST API ใน Excel]]></title>
            <link>https://tklofb.medium.com/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%A5%E0%B8%B4%E0%B8%AA%E0%B8%97%E0%B9%8C%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%88%E0%B8%B2%E0%B8%81-rest-api-%E0%B9%83%E0%B8%99-excel-343da04fd693?source=rss-51a023198bc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/343da04fd693</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[macro]]></category>
            <category><![CDATA[vba]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[TLF]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 08:15:43 GMT</pubDate>
            <atom:updated>2021-01-10T08:15:43.405Z</atom:updated>
            <content:encoded><![CDATA[<p>ในการพัฒนาระบบนั้น บ่อยครั้งที่ต้องรองรับการ Import ข้อมูลเข้าระบบเป็น Excel ไฟล์ ซึ่ง Excel File ดังกล่าวมักจะมีข้อมูลพื้นฐานบางส่วนซึ่งหากเราทำเป็นลิสท์ใน Excel ไว้และวันนึงข้อมูลดังกล่าวมีการเปลี่ยนแปลง เรามักจะต้องมาอัพเดทไฟล์ใหม่อยู่เสมอ ๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/1*_-alOUznCDXcb27gimIDSQ.png" /><figcaption>ภาพตัวอย่างลิสท์ข้อมูลพื้นฐานบนไฟล์ Excel</figcaption></figure><p>เพราะงั้นวันนี้เราจะลองทำการดึงข้อมูลพื้นฐานเหล่านี้ผ่าน API เพื่อลดปัญหาดังกล่าวกันครับ</p><p>เบื้องต้นผมมี API สำหรับลองเรียกที่จะส่งข้อมูลเป็น Array ให้ เตรียมไว้ดังนี้ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*4VP7yoF69X4cHg-2XMFsVA.png" /></figure><p><strong><em>ขั้นตอนที่ 1</em></strong> เริ่มจากสร้างไฟล์ Excel ขึ้นมาและสร้าง Column Employee ไว้ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/129/1*uYP2YA3pyV9qzDZRLhNE6g.png" /></figure><p><strong><em>ขั้นตอนที่ 2 </em></strong>ไปยัง Tab Formula แล้วเลือก Defined Name เพื่อสร้างแหล่งข้อมูล โดยใส่ข้อมูลลงไปตามภาพครับ โดยเราจะใช้ Sheet2!$A:$A เพื่อเก็บข้อมูลสำหรับทำเป็นลิสท์ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*4TjfPkIOl7HgMpIej3fhAQ.png" /></figure><p><strong><em>ขั้นตอนที่ 3 </em></strong>ทำกการสร้างลิสท์ด้วยคลุม Cells ที่คอลัมน์ A ใน Sheet 1 ทั้งหมด จากนั้นเลือกที่ Data Validation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*CUc_PMDOuCzQsZzOptmcdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*ZFbMsuLIQJyLQS2kvGie3A.png" /></figure><p><strong><em>ขั้นตอนที่ 4 </em></strong>เลือกข้อมูลตามภาพเพื่อสร้าง list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*ynEz63hogx89x9zJyuWLjw.png" /></figure><p><strong><em>ขั้นตอนที่ 5 </em></strong>วาดปุ่มสำหรับใช้ดึงข้อมูล (หากใครไม่มีแถบ Developer ให้ไปทำการเปิดขึ้นมาก่อนจาก Files =&gt; Options =&gt; Customize Ribbon นะครับ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*_4y2RWqKjJkfo7biFkuEsw.png" /></figure><p><strong><em>ขั้นตอนที่ 6 </em></strong>กด Assign macro =&gt; New เพื่อทำการสร้างฟังก์ชันให้ปุ่มทำงานเพื่อไปเรียกข้อมูลจาก API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*ilE0oIsHE4sp_bMnS19URg.png" /></figure><p><strong><em>ขั้นตอนที่ 7 </em></strong>Download Lib สำหรับแปลงข้อมูล Json จาก <a href="https://github.com/VBA-tools/VBA-JSON">https://github.com/VBA-tools/VBA-JSON</a> จากนั้นในหน้าต่าง Macro ที่เปิดมาจากขั้นตอน 6 ให้กด File =&gt; Import File และเลือกไฟล์ JsonConverter.bas เพื่อ Import Lib สำหรับใช้งาน</p><p><strong><em>ขั้นตอนที่ 8 </em></strong>จากนั้นในหน้าต่าง Macro กดที่ Tools References และเลือก Microsoft Scripting Runtime</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*i_fmLZsOC6yG2uXM6UBKrQ.png" /></figure><p><strong><em>ขั้นตอนที่ 9 </em></strong>ทำการพิมพ์โค้ดดังนี้ (Button2_Click ในที่นี้คือฟังก์ชันที่เกิดจากตอนกด Assign Macro ครับ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*qbsQaXBpBBva5t5ZffFkMA.png" /><figcaption>เราจะใช้ MSXML2.ServerXMLHTTP ในการสร้าง Request ไปยัง API ที่มีการเตรียมไว้ <a href="http://localhost:56618/api/values">http://localhost:56618/api/values</a> จากนั้นใช้ JsonConverter สำหรับอ่าน Json ครับ</figcaption></figure><p><strong><em>ขั้นตอนที่ 10 </em></strong>ทำการทดสอบโดยกดปุ่มที่สร้างขึ้นจะพบว่าข้อมูลจะถูก write ไว้ใน Sheet ที่ 2 และทำให้ข้อมูลแสดงในลิสท์ที่ผูกไว้เรียบร้อยครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*WqfJN99qDmYQQ9FtqbPAiA.png" /></figure><p>สำหรับท่านใดที่อาจนำไปใช้ในการ Post ข้อมูลไปบันทึกที่ API เลยก็สามารถนำวิธีการเรียก API ไปประยุกต์ได้ครับ ทั้งนี้อาจต้องมีการเพิ่มเติมเรื่องการทำ Authentication เพิ่มเติมไปด้วยครับ</p><p><strong>References:</strong></p><p><a href="https://stackoverflow.com/questions/48747859/xhr-request-response-text-has-unexpected-character-set">https://stackoverflow.com/questions/48747859/xhr-request-response-text-has-unexpected-character-set</a><br><a href="https://stackoverflow.com/questions/11242399/blank-values-in-excel-data-validation-drop-down-list">https://stackoverflow.com/questions/11242399/blank-values-in-excel-data-validation-drop-down-list</a><br><a href="https://www.contextures.com/xldataval01.html">https://www.contextures.com/xldataval01.html</a><br><a href="https://github.com/VBA-tools/VBA-JSON">https://github.com/VBA-tools/VBA-JSON</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=343da04fd693" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[มารู้จัก Web.Config File Transformations กันเถอะ]]></title>
            <link>https://tklofb.medium.com/%E0%B8%A1%E0%B8%B2%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-web-config-file-transformations-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0-6d034812d766?source=rss-51a023198bc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d034812d766</guid>
            <category><![CDATA[visual-studio]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[aspnet]]></category>
            <category><![CDATA[dot-net-framework]]></category>
            <dc:creator><![CDATA[TLF]]></dc:creator>
            <pubDate>Sun, 11 Aug 2019 08:51:01 GMT</pubDate>
            <atom:updated>2019-08-11T08:51:01.113Z</atom:updated>
            <content:encoded><![CDATA[<p>ในการพัฒนา Web Application เรามักจะมี Environment ต่าง ๆ มากมายไม่ว่าจะเป็น Develop, Test, Customer Site Test, Production, บลา ๆ ๆ</p><p>หลาย ๆ ท่านน่าจะเคยประสบปัญหาเผลอเอาไฟล์ web.config ที่ใช้ในเครื่องตัวเองทับไฟล์ web.config ในขณะที่ deploy จนต้องหัวร้อนหาทางใส่ Config กลับให้เหมือนเดิม</p><p>วันนี้เราจะมีรู้จักกับ Web.config File Transformations ซึ่งจะช่วยแก้ปัญหานี้กันครับ</p><p>Web.config File Transformation เป็นฟังก์ชันที่ช่วยในการปรับไฟล์ Web.config ในขณะที่เรา Publish ให้ตรงกับ Environment ที่เราต้องการโดยอัตโนมัติ ทำให้เราสามารถ deploy ได้อย่างสบายใจครับ</p><p>ทั้งนี้ตัวอย่างที่ทำให้ดูนี้จะเป็นการใช้ Visual Studio 2019 แต่จริง ๆ ฟังก์ชันนี้มีมาตั้งแต่ 2010 เลยครับ</p><p><strong>มาเริ่มกันเลยดีกว่า</strong></p><p>1.เริ่มจากสร้าง Project เป็น Web Application ขึ้นมา จะสังเกตุว่า Web.config เราจะมีไฟล์ลูกแยกอยู่อีกสองไฟล์ได้แก่ Web.Debug.config และ Web.Release.config ซึ่งสองไฟล์นี้จะถูกใช้งานเมื่อเราจะ Publish ตัวเว็บครับ ถ้าหากไฟล์ไม่แสดงลองคลิก icon ที่หมายเลข 2 ดูครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*sznx0vh9ekXyjjHwFzgPBw.png" /></figure><p>2.ลองเติม Code นี้ลงใน Web.config</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*N1OzkBlKDlA3TToZp8Y8gA.png" /></figure><p>3.ลองเปิดไฟล์ Web.Release.config ขึ้นมาและลองเติมเข้าไปตามนี้ เพื่อให้ได้ไฟล์ที่ต้องการเมื่อ Publish ด้วย Release โดยตัวอย่างจะเป็นการ</p><ul><li><strong>แก้ไข Connection String</strong> โดยใช้ xdt:Transform=“SetAttributes” xdt:Locator=“Match(name)” เพื่อบอกว่าจะเป็นการทับ Attribute โดยดูจาก Property “name” ที่ตรงกัน</li><li><strong>ลบ Debug mode</strong> <strong>จาก Tag Compilation</strong> โดยใช้ xdt:Transform=“RemoveAttributes(debug)” เพื่อลบ Attribute “debug” ออก</li><li><strong>เพิ่ม system.webserver </strong>โดยใช้ xdt:Transform=“Insert” เพื่อบอกให้เพิ่มส่วนนี้ลงไป</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*fyVNwcXEyYWnJrjeSKoI8g.png" /></figure><p>4.มาลอง Publish กันเลย (เลือก Configuration Release เพื่อให้เรียกใช้ Web.Release.config)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*TsIX6fs69a4FqM471LFd7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*84kel5LC7PYcIQqEKLDdcw.png" /></figure><p>5. ลองดูผลลัพธ์ไฟล์ web.config ที่ Publish ออกมา สังเกตุว่าจะเป็นตามที่เรา Config ไว้ที่ Web.Release.config ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*b133UjnzcayuVjUnkc0Q9g.png" /></figure><p>นอกจากนี้สามารถดูตัวอย่าง Syntax การ Transform อื่น ๆ ได้จากที่นี่ครับ <a href="https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110)">https://docs.microsoft.com/en-us/previous-versions/aspnet/dd465326(v=vs.110)</a></p><p><strong>แถม</strong></p><p>เราสามารถเพิ่ม Environment ได้เองโดยการเพิ่ม Configuration ใน Configuration Manager จากนั้นกดคลิกขวาที่ Web.config =&gt;Add config transform ได้ครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*PwI20oAvwc8w5GtQlgQTYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*PBqYy2O0MA90KHp6HrdoZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*jfl2yRFNkOIcMeDDWp_A9g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d034812d766" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>