-- Connection string ผมเพิ่งเริ่มศึกษาจากใน web thaicreate นี่แหละครับ ขอบคุณสำหรับบทความดีๆ ครับ
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function getDetailUser(ByVal uid As String) As DataTable
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim strConn As String
Dim strSql As New StringBuilder
strConn = "Server=localhost;UID=sa; " _
& "PASSWORD=sa2008;database=DBequipmnt;Max Pool Size=400;Connect Timeout=600"
strSql.Append(" SELECT * FROM usermst (NOLOCK)")
strSql.Append(" WHERE user_id = '" & uid & "'")
objConn.ConnectionString = strConn
With objCmd
.Connection = objConn
.CommandText = strSql.ToString
.CommandType = CommandType.Text
End With
da.SelectCommand = objCmd
da.Fill(ds)
dt = ds.Tables(0)
da = Nothing
objConn.Close()
objConn = Nothing
Return dt
End Function
End Class
Imports System.Data
Imports System.Data.SqlClient
Partial Class UserDetail
Inherits System.Web.UI.Page
' Call webservice
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim mySer As New myService.Service
Dim dt As New DataTable
If txtUser.Text <> "" Then
dt = mySer.getDetailUser(Me.txtUser.Text) 'เรียก webservice โดยส่งค่า userid
If dt.Rows.Count > 0 Then
Me.lblName.Text = dt.Rows(0)("sname").ToString
Me.lblPost.Text = dt.Rows(0)("post").ToString
Me.lblDept.Text = dt.Rows(0)("dept").ToString
Me.lblIP.Text = dt.Rows(0)("com_ip").ToString
Me.lblPic.Text = dt.Rows(0)("pic_sign").ToString
End If
Else
Message(Page, "กรุณากรอกข้อมูลด้วย ครับ")
txtUser.Focus()
End If
End Sub
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtUser.Text = ""
lblName.Text = ""
lblPost.Text = ""
lblDept.Text = ""
lblIP.Text = ""
lblPic.Text = ""
txtUser.Focus()
End Sub
Private Sub Message(ByVal p As Page, ByVal str As String)
Dim strScript As String
strScript = "<script language=javascript> alert(""" & str & """) </script>"
p.Response.Write(strScript)
End Sub
End Class