ได่ตัวอย่างมาค่ะ และมีปัญหาอยู่ว่าเวลาใช้ where มันจะรันไม่ผ่านแจ้งติดตรง ติดต่อกับฐานข้อมูลไม่ได้ แต่พอลบ where ออกก็สามารถรันผ่านและโชว์ข้อมูลได้ ***แต่มันต้องใช้ where อะค่ะไม่ทราบใครจะแนะนำได้บ้าง
Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Private conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" & Server.MapPath("thailand.mdb")
'Private conStr As String = "Server=(local);database=reservation_system;uid=rssadmin;password=PAma22"
' Protected WithEvents Dropdownlist1 As System.Web.UI.WebControls.DropDownList
' Protected WithEvents Dropdownlist2 As System.Web.UI.WebControls.DropDownList
' Protected WithEvents Dropdownlist3 As System.Web.UI.WebControls.DropDownList
Private Shared dsChild As New DataSet
Dim ds1 As New DataSet()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
'Put user code to initialize the page here
If IsPostBack = False Then
BindDropDownList()
End If
End Sub
Private Sub BindDropDownList()
Dim conn As New OleDbConnection(conStr)
conn.Open()
Dim ds As New DataSet()
Dim da As New OleDbDataAdapter("Select * From geography ", conn)
da.Fill(ds, "geography")
droBuild.DataSource = ds.Tables("geography")
droBuild.DataTextField = ("GEO_NAME")
droBuild.DataValueField = ("GEO_ID")
droBuild.DataBind()
da.Dispose()
conn.Dispose()
BindDropDownListChild()
End Sub
Private Sub BindDropDownListChild()
Dim conn As New OleDbConnection(conStr)
conn.Open()
Dim da1 As New OleDbDataAdapter("Select * From province Where GEO_ID ='" & droBuild.SelectedValue & "'", conn) '***ตรงนี้ค่ะ***
dsChild = New DataSet
da1.Fill(dsChild, "province")
droFloor.Items.Clear()
droFloor.DataSource = dsChild.Tables("province")
droFloor.DataTextField = ("PROVINCE_NAME")
droFloor.DataValueField = ("GEO_ID") ' binding
droFloor.DataBind()
da1.Dispose()
conn.Dispose()
'DisplayImage()
End Sub
'Private Sub DisplayImage()
'Dim sSel As String = "FLOOR = " & droFloor.SelectedValue
' If dsChild.Tables.Count > 0 Then
' Dim dr() As DataRow = dsChild.Tables(0).Select(sSel)
'Dim Path As String Path = IIf(dr.Lenght > 0, dr(0)("MAP_PATH"), String.Empty).ToString()
' If dr.Length > 0 Then
' Dim Path As String = dr(0)("MAP_PATH")
' Response.Write(Path)
' End If
' End If
' End Sub
Private Sub DropDownList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ctrlId As String = CType(sender, DropDownList).ID.ToLower()
Select Case ctrlId
Case "droBuild"
BindDropDownListChild()
'droFloor.DataBind()
Case "droFloor"
' DisplayImage()
Case "db"
Case Else
End Select
End Sub
End Class
หรือว่ามันจะเกี่ยวกับการใช้
Dim da1 As New OleDbDataAdapter("Select * From province Where GEO_ID ='" & droBuild.SelectedValue & "'", conn)
แทนการใช้
Dim da1 As New SqlDataAdapter("Select * From province Where GEO_ID ='" & droBuild.SelectedValue & "'", conn) ช่วยแนะนำหน่อย