วันพุธที่ 2 พฤษภาคม พ.ศ. 2561

แก้ไข collation ในฐานข้อมูล SQL Server ปัญหาแสดงข้อมูลเป็นเครื่องหมายคำถาม ?????

ปัญหานี้เกิดจากที่ผม ส่งค่า String จากโค้ดคำสั่งของ .net เพื่อให้เพิ่มข้อมูลในฐานข้อมูล SQL Server ปรากฏว่าเมื่อแสดงกลับเป็นเครื่องหมายคำถาม วิธีแก้ไขคือ ใช้คำสั่งใน New Query  ตัวอย่างเช่น

ALTER DATABASE ชื่อฐานข้อมูล COLLATE Thai_CI_AS;

บางครั้งใช้คำสั่งนี้แล้ว มีแจ้ง Error ขึ้นมา อาจเกิดจากฐานข้อมูลมีการเรียกใช้อยู่ ให้เคียร์ User ออกก่อน (ผมใช้วิธี Rename ในไฟล์ web.config)

วันศุกร์ที่ 1 ธันวาคม พ.ศ. 2560

วิธีการส่งค่าแบบ Ajax ผ่าน JQuery ไปยัง server side ด้วย Asp.net

<form id="form1" runat="server">

                <label>ชื่อ-สกุล:</label>
                <asp:TextBox ID="txtFullName" runat="server" Width ="250" ></asp:TextBox>

                <label>ชื่อเรียก:</label>
                <asp:TextBox ID="txtNicName" runat="server" Width ="250"></asp:TextBox>

                <label>การศึกษา:</label>
                <asp:DropDownList ID="ddl_education" runat="server"   Width ="250" >
                    <asp:ListItem Text="1. ประถมศึกษา" Value="1"></asp:ListItem>
                    <asp:ListItem Text="2. มันธยมศึกษา" Value="2"></asp:ListItem>
                    <asp:ListItem Text="3. ปริญญาตรี" Value="3"></asp:ListItem>
                    <asp:ListItem Text="4. ปริญญาเอก" Value="4"></asp:ListItem>
                </asp:DropDownList>

            <asp:Button ID="btnOK" runat="server"  OnClientClick="return false;"
                Text="บันทึก" />


    </form>


  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type = "text/javascript">

        $("#<%=btnOK.ClientID%>").click(function () {
            doSaveData();
        });

       
        function doSaveData() {
          
            var _fullName = document.getElementById('<%=txtFullName.ClientID%>').value;
            var _education = document.getElementById('<%=ddl_education.ClientID%>').value;
            var _nicName = document.getElementById('<%=txtNicName.ClientID%>').value;

            $.ajax({
                type: 'POST',
                url: '/ajax_client_to_code.aspx/saveData',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify({
                    fullName: _fullName,
                    education: _education,
                    nicName: _nicName
                }),
                dataType: 'json',
                success: OnSuccess
            });

        }

        function OnSuccess(response) {
            document.getElementById("<%=btnOK.ClientID%>").innerHTML = 'บันทึกข้อมูลแล้ว';        
               // window.location.href = "";
        }


</script>


***************** VB.NET Code ***********************

Public Class ajax_client_to_code
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

<System.Web.Services.WebMethod()>
    Public Shared Function saveData(fullName As String, education As String, nicName As String) As String
        Dim result As String = "ok"

        Return result
    End Function

End Class

วันเสาร์ที่ 23 กรกฎาคม พ.ศ. 2559

ASP.NET: ดึง RSS มาแสดงใน Repeater ด้วยคำสั่ง VB.NET

เนื่องจากการที่ผมไม่เคยเขียนคำสั่ง สำหรับดึง RSS มาแสดงบนเว็บไซต์ที่เขียนด้วย ASP.NET ต้องวิจัยอยู่นาน 3 ชั่วโมง ซึ่งก็คุ้มค่าพอสมควร เพราะทำให้ผมเข้าใจการเขียนคำสั่งติดต่อกับ RSS จริงๆคือ เป็นโครงสร้างไฟล์ XML ที่มีรูปแบบตามมาตรฐาน RSS ทำให้สามารถต่อยอดและแสดงผลโดยใช้เครืองมือ Repeater  จากที่ผมใช้เวลา 3 ชั่วโมง หวังว่าท่านที่สนใจสามารถนำโค้ดนี้ไปใช้งานจะประหยัดเวลามากขึ้นนะครับ ^^

***************** VB.NET ************************* 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strURL As String
        Dim ds As New DataSet()
        strURL = "http://rssfeeds.sanook.com/rss/feeds/sanook/hitech.computer.index.xml"


        Dim reader As XmlTextReader = New XmlTextReader(strURL)
        ds.ReadXml(reader)

        myRepeater_rss_News_it.DataSource = ds.Tables("item")
        myRepeater_rss_News_it.DataBind()


        ds = Nothing
End Sub
***************** ASP.NET *************************
<asp:Repeater id="myRepeater_rss_News_it" runat="server">
<ItemTemplate>
    <p><%# Eval("title")%></p>
    <p><%# Eval("description")%></p>
    <p><%# Eval("link")%></p>
       <hr />
</ItemTemplate>
</asp:Repeater>

ลิงค์ตัวอย่าง RSS อื่นๆ:
http://www.thaiware.com/rss/rss_latestPost_news.php
https://www.blognone.com/atom.xml

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...