Ich habe es auf MySQL und vb angepasst, aber wo muss es hin?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
test()
End If
End Sub
Protected Sub test()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim strQuery As String = "select * from Name where Id=@ID"
Dim con As MySqlConnection = New SqlConnection(strConnString)
Dim cmd As MySqlCommand = New MySqlCommand()
cmd.Parameters.AddWithValue("@ID", MySqlDbType.Decimal).Value = Region.SelectedItem.Value
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DataListName.DataSource = cmd.ExecuteReader()
DataListName.DataBind()
' Throw ex
Catch ex As Exception
Finally
con.Close()
con.Dispose()
End Try
End Sub
Protected Sub Region_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
test()
End Sub
ganzer Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class hauptseite
Inherits System.Web.UI.Page
Public Property MyVariablen As New Variablen()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
DropDownLand.AppendDataBoundItems = True
Dim strConnString As [String] = ConfigurationManager _
.ConnectionStrings("conString").ConnectionString
Dim strQuery As [String] = "Select LandDE, idLand from Campingplatz Group BY LandDE ORDER BY LandDE ASC"
Dim con As New MySqlConnection(strConnString)
Dim cmd As New MySqlCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DropDownLand.DataSource = cmd.ExecuteReader()
DropDownLand.DataTextField = "LandDE"
DropDownLand.DataValueField = "idLand"
DropDownLand.DataBind()
Catch ex As Exception
'Throw ex
Finally
con.Close()
con.Dispose()
End Try
End If
End Sub
Protected Sub idLand_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DropDownBundesland.Items.Clear()
DropDownBundesland.Items.Add(New ListItem("--Select Bundesland--", ""))
DropDownRegion.Items.Clear()
DropDownRegion.Items.Add(New ListItem("--Select Region--", ""))
DropDownBundesland.AppendDataBoundItems = True
Dim strConnString As [String] = ConfigurationManager _
.ConnectionStrings("conString").ConnectionString
Dim strQuery As [String] = "Select Bundesland, idBundesland from Campingplatz where idLand = @LandID Group BY Bundesland ORDER BY Bundesland ASC"
Dim con As New MySqlConnection(strConnString)
Dim cmd As New MySqlCommand()
cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DropDownBundesland.DataSource = cmd.ExecuteReader()
DropDownBundesland.DataTextField = "Bundesland"
DropDownBundesland.DataValueField = "idBundesland"
DropDownBundesland.DataBind()
If DropDownBundesland.Items.Count > 1 Then
DropDownBundesland.Enabled = True
Else
DropDownBundesland.Enabled = False
DropDownRegion.Enabled = False
End If
Catch ex As Exception
'Throw ex
Finally
con.Close()
con.Dispose()
End Try
End Sub
Protected Sub idBundesland_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
DropDownRegion.Items.Clear()
DropDownRegion.Items.Add(New ListItem("--Select Region--", ""))
DropDownRegion.AppendDataBoundItems = True
Dim strConnString As [String] = ConfigurationManager _
.ConnectionStrings("conString").ConnectionString
Dim strQuery As [String] = "Select Region, idRegion, idBundesland, idLand from Campingplatz where idLand =@LandID and idBundesland = @BundeslandID Group BY Region ORDER BY Region ASC"
Dim con As New MySqlConnection(strConnString)
Dim cmd As New MySqlCommand()
cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
cmd.Parameters.AddWithValue("@BundeslandID", MySqlDbType.Decimal).Value = DropDownBundesland.SelectedItem.Value
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DropDownRegion.DataSource = cmd.ExecuteReader()
DropDownRegion.DataTextField = "Region"
DropDownRegion.DataValueField = "idRegion"
DropDownRegion.DataBind()
If DropDownRegion.Items.Count > 1 Then
DropDownRegion.Enabled = True
Else
DropDownRegion.Enabled = False
End If
Catch ex As Exception
'Throw ex
Finally
con.Close()
con.Dispose()
End Try
End Sub
Protected Sub idRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As [String] = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim strQuery As [String] = "Select * from Campingplatz where idLand =@LandID and idBundesland = @BundeslandID and idRegion = @RegionID ORDER BY Name ASC"
Dim con As New MySqlConnection(strConnString)
Dim cmd As New MySqlCommand()
cmd.Parameters.AddWithValue("@LandID", MySqlDbType.Decimal).Value = DropDownLand.SelectedItem.Value
cmd.Parameters.AddWithValue("@BundeslandID", MySqlDbType.Decimal).Value = DropDownBundesland.SelectedItem.Value
cmd.Parameters.AddWithValue("@RegionID", MySqlDbType.Decimal).Value = DropDownRegion.SelectedItem.Value
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
Try
con.Open()
DataListName.DataSource = cmd.ExecuteReader()
DataListName.DataBind()
Catch ex As Exception
'Throw ex
Finally
con.Close()
con.Dispose()
End Try
End Sub
End Class
Gruss Lothar