Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/10/2011, 07:44
Avatar de stuart_david3
stuart_david3
 
Fecha de Ingreso: agosto-2011
Mensajes: 215
Antigüedad: 12 años, 7 meses
Puntos: 1
Respuesta: Problema al conectarme a otra IP con SQL 2008 y VB 2010

Bueno, lo que yo quería era enlazar a mi base de datos mediante la vista de diseño del ListBox, pero desafortunadamente ocurre el error que puse al inicio del tema, pues total lo hice desde código y funciona aquí se los dejo por si a alguien le sirve :p...

Código ASP:
Ver original
  1. <%@ Import Namespace="System.Data.SQLClient" %>
  2. <script language="vbscript" runat="server">
  3. Sub Page_Load(Sender As Object, E As EventArgs)
  4.         Dim conn As SqlConnection =
  5.          New SqlConnection("server=10.11.2.49;database=extractor;User ID=sa;Password=administrador;Trusted_Connection=no")
  6.         Dim sql As String =
  7.          "Select b_traba1.rpe, b_traba1.nomtrab, b_traba1.pattrab, b_traba1.mattrab, b_traba1.fe_antre, b_traba1.rfc, b_traba2.calletra, b_traba2.afilimss, b_traba1.cl_tipco,b_traba1.cl_zona FROM b_traba1,b_traba2 WHERE b_traba1.cl_tipco IN (1,4,7,9) AND b_traba1.rpe=b_traba2.rpe AND b_traba1.cl_zona = 'DU020' AND b_traba1.cl_sitla is null GROUP BY b_traba1.rpe, b_traba1.nomtrab, b_traba1.pattrab, b_traba1.mattrab, b_traba1.fe_antre, b_traba1.rfc, b_traba2.calletra, b_traba2.afilimss, b_traba1.cl_tipco,b_traba1.cl_zona"
  8.         Dim dr As New SqlCommand(sql, conn)
  9.         Dim reader As SqlDataReader
  10.         Dim values As ArrayList = New ArrayList()
  11.         Dim values2 As ArrayList = New ArrayList()
  12.         conn.Open()
  13.         reader = dr.ExecuteReader()
  14.         While reader.Read()
  15.             values.Add(reader.Item("rpe").ToString() & " " & reader.Item("nomtrab").ToString())
  16.             values2.Add(reader.Item("afilimss").ToString() & " " & reader.Item("calletra").ToString())
  17.         End While
  18.         lb.DataSource = values
  19.         lb.DataBind()
  20.         lb2.DataSource = values2
  21.         lb2.DataBind()
  22.         conn.Close()
  23.         reader.Close()
  24.     End Sub
  25. </script>
  26. <html>
  27. <head>
  28. <title>ListBox using SQLDataReader</title>
  29. </head>
  30. <body>
  31.     <asp:Label ID="Label1" runat="server" Text="RPE del Empleado"></asp:Label>
  32. <form id="Form1" method="post" runat="server">
  33. <asp:ListBox id="lb" SelectionMode="Multiple" runat="server" Height="643px"
  34.     Width="196px"/>
  35.     <asp:ListBox id="lb2" SelectionMode="Multiple" runat="server" Height="643px"
  36.     Width="196px"/>
  37. </form>
  38. </body>
  39. </html>

Ahora mi duda es la siguiente, como puedo consultar registros de mi base de datos en base a los listbox que, por ejemplo seleccione con el mouse y le de click a un botón, disculpen las molestias buscaré como hacerlo, pero si alguien pudiese ayudarme se lo agradecería mucho...

Gracias por tu respuesta mackbeth...