Ver Mensaje Individual
  #21 (permalink)  
Antiguo 18/10/2011, 11:18
Avatar de stuart_david3
stuart_david3
 
Fecha de Ingreso: agosto-2011
Mensajes: 215
Antigüedad: 12 años, 8 meses
Puntos: 1
Respuesta: Generar listbox en base a otro listbox en una base de datos sql, asp.net

rikakashi Muchas gracias por tanta ayuda y disculpa también por tantas molestias, desafortunadamente sigo con el mismo problema mi listbox1 esta con sus campos pero el 2 se rehúsa a aceptar los campos que le mando ... No se que pasa :s... Aquí dejó el código que puse... De nuevo muchísimas gracias:

Código ASP:
Ver original
  1. <%@ Import Namespace="System.Data" %>
  2.  
  3. <%@ Import Namespace="System.Data.SQLClient" %>
  4. <script language="vbscript" runat="server">
  5. Sub Page_Load(Sender As Object, E As EventArgs)
  6.         Dim reader As SqlDataReader
  7.         Dim values As ArrayList = New ArrayList()
  8.         Dim conn As SqlConnection =
  9.          New SqlConnection("server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no")
  10.         Dim sql As String =
  11.          "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES GROUP BY TABLE_NAME"
  12.         Dim dr As New SqlCommand(sql, conn)
  13.         conn.Open()
  14.  reader = dr.ExecuteReader()
  15.         While reader.Read()
  16.             values.Add(reader.Item("TABLE_NAME").ToString())
  17.         End While
  18.         lb1.DataSource = values
  19.         lb1.DataBind()
  20.         reader.Close()
  21.     End Sub
  22. </script>
  23. <html>
  24. <head>
  25. <title>Tablas y Columnas</title>
  26. </head>
  27. <body>
  28.     <asp:Label ID="Label1" runat="server" Text="RPE del Empleado"></asp:Label>
  29. <form id="Form1" method="post" runat="server" name="ListEnlaza">
  30. <asp:ListBox id="lb1" SelectionMode="Multiple" runat="server" Height="217px"
  31.     Width="196px"/>
  32.     <asp:ListBox id="lb2" SelectionMode="Multiple" runat="server" Height="147px"
  33.     Width="196px"/>
  34. <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  35. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="list2"/>
  36. <script language="vbscript" runat="server">
  37. sub list2 (ByVal sender As Object, ByVal e As EventArgs)
  38.        Dim reader As SqlDataReader
  39.         Dim values2 As ArrayList = New ArrayList()
  40.         Dim conn As SqlConnection =
  41.         New SqlConnection("server=myhost;database=mydb;User ID=myuser;Password=mypass;Trusted_Connection=no")
  42.         conn.Open()
  43.         DIM CADENA AS STRING = Convert.ToString(lb1.SELECTEDITEM)
  44.   Dim sql2 As String =
  45.          "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =' & CADENA & ' GROUP BY COLUMN_NAME"
  46.         Dim dr2 As New SqlCommand(sql2, conn)
  47.                  
  48.         reader = dr2.ExecuteReader()
  49.         While reader.Read()
  50.             values2.Add(reader.Item("COLUMN_NAME").ToString())
  51.         End While
  52.        
  53.         lb2.DataSource = values2
  54.         lb2.DataBind()
  55.         reader.Close()
  56.         conn.Close()
  57. End Sub
  58. </script>
  59. </form>
  60. </body>
  61. </html>