Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtID.Focus()
End Sub
Protected Sub btnShow_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnShow.Click
Dim myCusDetail As New cusDetail.getCustomerDetail
Dim dt As DataTable = myCusDetail.DetailCustomer(Me.txtID.Text)
If dt.Rows.Count > 0 Then
' Me.lblID.Text = dt.Rows(0)("ID").ToString()
Me.lblPartNo.Text = dt.Rows(0)("PartNo").ToString()
lblPartNo.BackColor = Drawing.Color.Brown
Me.lblFun.Text = dt.Rows(0)("Func").ToString()
lblFun.BackColor = Drawing.Color.Brown
Me.lblHan.Text = dt.Rows(0)("Handle").ToString()
lblHan.BackColor = Drawing.Color.Brown
Me.lblMir.Text = dt.Rows(0)("Mirror").ToString()
lblMir.BackColor = Drawing.Color.Brown
Me.lblBarcodeID.Text = dt.Rows(0)("UserDef1").ToString()
'.Me.lblUsed.Text = dt.Rows(0)("Used").ToString()
lblBarcodeID.BackColor = Drawing.Color.Brown
End If
grdShow.DataSource = dt
grdShow.DataBind()
End Sub
Code ฝั่ง Service_Server Code (VB.NET)
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class getCustomerDetail
Inherits System.Web.Services.WebService
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
<WebMethod()> _
Public Function DetailCustomer(ByVal strID As String) As DataTable
Dim ds As New DataSet
Dim dt As DataTable
Dim strConnString As String
Dim strSQL As New StringBuilder
' strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strConnString = "server=192.168.0.23;uid=sa;pwd=abc1234;database=db565W;"
strSQL.Append(" SELECT * FROM tape ")
strSQL.Append(" WHERE [ID] = '" & strID & "' ")
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL.ToString()
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dt = ds.Tables(0)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
'Dim json = JsonConvert.SerializeObject(dt, Formatting.Indented)
' Return json
Return dt
End Function
ทาง Client จะต้องสร้าง Form หลาย ๆ Form สำหรับการ Input ข้อมูลครับ ส่วน Web Service Server อาจจะทำแค่ URL เดียว แต่ประกอบด้วยหลาย ๆ Function เช่นการ Insert,Update,Delete ครับ