Ver Mensaje Individual
  #15 (permalink)  
Antiguo 14/10/2011, 14:31
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

Hola rikakashi gracias por tu respuesta. Pues lo coloque como dijiste, solo que agregue las variables del reader y la conexión en el evento del botón, pero el mismo resultado al darle clic a dicho botón, mi otro listbox sigue en blanco ... Aquí dejo el código por si me pudieran ayudar a resolver mi duda n_n... Gracias de nuevo...


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