Protected Sub ddl_Company_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_Company.DataBound
ddl_Company.Items.Insert(0, "<--- กรุณาเลือกสาขาบริษัท --->")
End Sub
Protected Sub ddl_Company_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_Company.SelectedIndexChanged
Dim company_id As Int16 = CShort(ddl_Company.SelectedItem.Value)
Dim strConn As String
strConn = WebConfigurationManager.ConnectionStrings("WEBConnectionString").ConnectionString
Dim Conn As New SqlConnection(strConn)
Conn.Open()
Dim strSQL As String
strSQL = "SELECT company_fullname,company_address,company_tel,company_fax,company_email FROM TB_Mod_Company"
strSQL &= " where (company_id = @company_id)"
Dim cmd As New SqlCommand(strSQL, Conn)
cmd.Parameters.Add("@company_id", SqlDbType.NChar).Value = company_id
Dim dr As SqlDataReader = cmd.ExecuteReader()
Dim CompanyDetails, company_fullname, company_address, company_tel, company_fax, company_email As String
If dr.Read Then
With dr
company_fullname = dr.Item("company_fullname").ToString
company_address = dr.Item("company_address").ToString
company_tel = dr.Item("company_tel").ToString
company_fax = dr.Item("company_fax").ToString
company_email = dr.Item("company_email").ToString
CompanyDetails = company_fullname + " " + "ที่อยู่ :" + company_address + " " + "เบอร์โทร :" + company_tel + " " + "เบอร์แฟกซ์ :" + company_fax + " " + "อีเมลล์ : " + company_email
txt_CompanyDetails.Text = CompanyDetails
End With
End If
Conn.Close()
Conn = Nothing
End SubCode (VB.NET)
Tag : ASP, Ms SQL Server 2008, Web (ASP.NET), VS 2010 (.NET 4.x)