Posts

Showing posts from November, 2010

Control SiteMapPath :: วิธีการใช้งาน

Image
    การเขียนเว็บไซด์เคยสับสนหรือเปล่า ว่าเอ๊!!! ตอนนี้เราอยู่ที่เมนูไหนหว่า?? เมื่อกี้คลิ๊กจาเมนูไหนมาหว่า?? ดังนั้น Control ที่ชื่อว่า SiteMapPath ช่วยคุณได้ดังนี้ เรามาดูวิธีสร้างกันเลยดีกว่า 1. ทำการสร้างเมนู และลิงค์ตามความต้องการ เอาไว้ที่ MasterPage 2. ทำการเพิ่มไฟล์ (Add New Item) ที่ชื่อว่า Site Map เข้ามาที่เว็บไซด์ และตั้งชื่อว่า Web.sitemap ตามนี้เลย 3. ทำการแก้ไขไฟล์ Web.sitemap โดยแก้ไขให้ทำการอ้างอิงกับ Menu ที่สร้างเอาไว้ในข้อที่ 1. 4. ทำการเพิ่ม Control ที่ชื่อว่า SiteMapPath และ SiteMapDataSource

การสร้าง และการเรียกใช้งาน Web Service

การสร้าง Web Service 1. สร้าง WebSite ใหม่ขึ้นมา แล้วให้เลือกเป็น ASP.NET Web Service 2. ตั้งชื่อ Class ตามใจชอบ ของเดิมๆคือ Public Class Service (สมมติแก้เป็น MyServiceClass) 3. ตั้งชื่อ Function ตามใจชอบ (แต่ให้เข้าใจล่ะกันไม่งั้นนานๆเข้างงตาย ^^") ของเดิมๆคือ     Public Function HelloWorld() As String         Return "Hello World Ja."     End Function 4. เราก็เริ่มเขียนโปรแกรมใน Function ได้เลย แต่อย่าลืมต้อง Return ด้วยเพราะว่ามันคือ Function นั่นเอง 5. การเขียน Web Service ของเราเสร็จสิ้นแล้ว ง่ายม่ะ อิอิ (อย่าลืม Upload ไปที่ WebServer ล่ะ) 6. สมมติคือ http://webserver/helloworld/ การเรียกใช้งาน Web Service 1. สร้าง WebSite ใหม่ขึ้นมา แล้วให้เลือกเป็น ASP.NET Web Site 2. ไปที่หน้าต่าง Solution Explorer แล้วคลิ๊กขวาเลือก Add Web Reference... 3. พิมพ์ URL ตามที่เราได้ทำการ Upload Web Service จะได้ http://webserver/helloworld/service.asmx และทำการแก้ไข Web reference name ตามใจชอบ (สมมติเป็น WServices) แล้วกด Add Reference 4. สร้างตัวแปรเพื่ออ้างอิง Web S

เพิ่มข้อมูลลงฐานข้อมูล โดยใช้ SqlCommand

1. ทำการ Imports Component ที่ต้องการใช้งาน Imports System.Data Imports System.Data.SqlClient 2. ประกาศข้อมูลการติดต่อฐานข้อมูลในไฟล์ web.config connectionStrings      add name="conn" connectionString="Data Source=SERVER_NAME;Initial Catalog=DB_NAME;Persist Security Info=True;User ID=userid;Password=password" providerName="System.Data.SqlClient"/ /connectionStrings 3. ประกาศตัวแปรที่จำเป็นต้องใช้งาน Public Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ConnectionString) Public Sql As String Public Da As SqlDataAdapter Public ds As New DataSet Public SqlTran As SqlTransaction Public drow As DataRow Public Ocb As SqlCommandBuilder Public Cmd As SqlCommand 4. เปิดการใช้งาน Transaction ก่อน Conn.Open() SqlTran = Conn.BeginTransaction 5. สร้าง DataSet เพื่อใช้ในการเพิ่มข้อมูล Sql = " Insert Into Table1(id,name) Values ('1','John') " Cmd = New SqlCommand(Sql,Conn) Cmd.Transac

Execute Command Prompt

Shutdown Computer Case 1. system.Diagnostics.Process.Start("shutdown","-s -t -m \\10.10.40.54") Case 2. Dim si As New System.Diagnostics.Process si.StartInfo.WorkingDirectory = "c:\\" si.StartInfo.UseShellExecute = False si.StartInfo.FileName = "cmd.exe" si.StartInfo.Arguments = "/c shutdown -s -m \\" si.StartInfo.CreateNoWindow = True si.StartInfo.RedirectStandardInput = True si.StartInfo.RedirectStandardOutput = True si.StartInfo.RedirectStandardError = True si.Start() si.Close()