• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Daten aus Datenbank auslesen

Status
Für weitere Antworten geschlossen.

BastiFantasti

Neues Mitglied
[FONT=Tahoma,Helvetica]Hallo zusammen! ich hab das Problem das ich auf Daten nich zugreifen kann bzw. an dem Quellcode etwas falsch ist?! Der Zugriff allgemein klappt an der Datenbank aber, bestimmte tabellen im browser ausgeben lassen(Request, Reqdate, Wo_Num) - funkioniert leider nicht. Ich bekomme nur einen Leeren Browser ausgegeben(ohne fehler) mit jedeglich 3 Textboxen die ich noch im Code erstellt habe. Wie gebe ich meine Tabelle aus von der DB und wo im Code? (vllt. Execute?)
Hier mal der Quellcode:
[/FONT]
[FONT=Tahoma,Helvetica]
HTML:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="VB" Debug="True" Strict="True" %>

<HTML>
 <HEAD>
  <title>SqlConnection-Demo</title>
  <script language="VB" runat="server">
  
Public Class Test
Inherits System.Web.UI.Page

Protected WithEvents WO_NUM As System.Web.UI.WebControls.TextBox
Protected WithEvents Reqdate As System.Web.UI.WebControls.TextBox
Protected WithEvents Request As System.Web.UI.WebControls.TextBox

Sub Page_Load (ByVal Sender As Object, _
               ByVal E As EventArgs)
               
   ' Verbindungszeichenfolge zusammensetzen
   Dim connStr As String 
   connStr = "server=bla1"
   connStr += "database=pubs;"
   connStr += "user id=trackit70;"
   connStr += "password=bla"
   
   Dim WO_NUM As System.Web.UI.WebControls.TextBox
   Dim Reqdate As System.Web.UI.WebControls.TextBox
   Dim Request As System.Web.UI.WebControls.TextBox
   
   Dim ausgabe As String
   Dim t As String
   Dim conn As New SqlConnection(connStr)
   
            
  ' Verbindung zur Datenbank herstellen
   Try 
      conn.Open()

   Dim SQLe As String
   SQLe = "SELECT WO_NUM, Reqdate, Request, mySqlConnection * FROM dbo.TASKS WHERE WO_NUM = 100"


          
          
   Catch exc As InvalidOperationException
      ' Die Verbindung ist bereits geöffnet.
      t += exc.Message
         
   Catch exc As SqlException
      t = "Fehler auf Verbindungsebene: " 
      t += exc.Message

      
   Finally 
      conn.Close()
      
   End Try
   ausgabe = t
End Sub

    End Sub
End Class
  </script>
 </HEAD>
 <body>
        <FORM id="Form1" method="post" runat="server">
  <H3>Verbindung mit Datenbank</H3>

  <P><asp:TextBox id="WO_NUM" runat="server"></asp:TextBox></P>
  <P><asp:TextBox id="Reqdate" runat="server"></asp:TextBox></P>
  <P><asp:TextBox id="Request" runat="server"></asp:TextBox></P>

        </FORM>
 </body>
</HTML>

danke schon mal im Voraus!
gruß Basti
[/FONT]
 
Zuletzt bearbeitet von einem Moderator:
Modedit: HTML Tags eingefügt. VB-Highlighting hinzugefügt:

So mit Highlighting:

  1. [FONT='Courier New',Courier,monospace]<%@ Import Namespace="System.Data.SqlClient" %> <%@ Page Language="VB" Debug="True" Strict="True" %> <HTML> <HEAD> <title>SqlConnection-Demo</title> <script language="VB" runat="server">[/FONT]
  2. [FONT='Courier New',Courier,monospace] [/FONT]
  3. [FONT='Courier New',Courier,monospace]Public Class Test[/FONT]
  4. [FONT='Courier New',Courier,monospace]Inherits System.Web.UI.Page[/FONT]
  5. [FONT='Courier New',Courier,monospace] [/FONT]
  6. [FONT='Courier New',Courier,monospace]Protected WithEvents WO_NUM As System.Web.UI.WebControls.TextBox[/FONT]
  7. [FONT='Courier New',Courier,monospace]Protected WithEvents Reqdate As System.Web.UI.WebControls.TextBox[/FONT]
  8. [FONT='Courier New',Courier,monospace]Protected WithEvents Request As System.Web.UI.WebControls.TextBox[/FONT]
  9. [FONT='Courier New',Courier,monospace] [/FONT]
  10. [FONT='Courier New',Courier,monospace]Sub Page_Load (ByVal Sender As Object, _[/FONT]
  11. [FONT='Courier New',Courier,monospace] ByVal E As EventArgs)[/FONT]
  12. [FONT='Courier New',Courier,monospace] [/FONT]
  13. [FONT='Courier New',Courier,monospace] ' Verbindungszeichenfolge zusammensetzen[/FONT]
  14. [FONT='Courier New',Courier,monospace] Dim connStr As String [/FONT]
  15. [FONT='Courier New',Courier,monospace] connStr = "server=bla1"[/FONT]
  16. [FONT='Courier New',Courier,monospace] connStr += "database=pubs;"[/FONT]
  17. [FONT='Courier New',Courier,monospace] connStr += "user id=trackit70;"[/FONT]
  18. [FONT='Courier New',Courier,monospace] connStr += "password=bla"[/FONT]
  19. [FONT='Courier New',Courier,monospace] [/FONT]
  20. [FONT='Courier New',Courier,monospace] Dim WO_NUM As System.Web.UI.WebControls.TextBox[/FONT]
  21. [FONT='Courier New',Courier,monospace] Dim Reqdate As System.Web.UI.WebControls.TextBox[/FONT]
  22. [FONT='Courier New',Courier,monospace] Dim Request As System.Web.UI.WebControls.TextBox[/FONT]
  23. [FONT='Courier New',Courier,monospace] [/FONT]
  24. [FONT='Courier New',Courier,monospace] Dim ausgabe As String[/FONT]
  25. [FONT='Courier New',Courier,monospace] Dim t As String[/FONT]
  26. [FONT='Courier New',Courier,monospace] Dim conn As New SqlConnection(connStr)[/FONT]
  27. [FONT='Courier New',Courier,monospace] [/FONT]
  28. [FONT='Courier New',Courier,monospace] [/FONT]
  29. [FONT='Courier New',Courier,monospace] ' Verbindung zur Datenbank herstellen[/FONT]
  30. [FONT='Courier New',Courier,monospace] Try [/FONT]
  31. [FONT='Courier New',Courier,monospace] conn.Open()[/FONT]
  32. [FONT='Courier New',Courier,monospace] [/FONT]
  33. [FONT='Courier New',Courier,monospace] Dim SQLe As String[/FONT]
  34. [FONT='Courier New',Courier,monospace] SQLe = "SELECT WO_NUM, Reqdate, Request, mySqlConnection * FROM dbo.TASKS WHERE WO_NUM = 100"[/FONT]
  35. [FONT='Courier New',Courier,monospace] [/FONT]
  36. [FONT='Courier New',Courier,monospace] [/FONT]
  37. [FONT='Courier New',Courier,monospace] [/FONT]
  38. [FONT='Courier New',Courier,monospace] [/FONT]
  39. [FONT='Courier New',Courier,monospace] Catch exc As InvalidOperationException[/FONT]
  40. [FONT='Courier New',Courier,monospace] ' Die Verbindung ist bereits geöffnet.[/FONT]
  41. [FONT='Courier New',Courier,monospace] t += exc.Message[/FONT]
  42. [FONT='Courier New',Courier,monospace] [/FONT]
  43. [FONT='Courier New',Courier,monospace] Catch exc As SqlException[/FONT]
  44. [FONT='Courier New',Courier,monospace] t = "Fehler auf Verbindungsebene: " [/FONT]
  45. [FONT='Courier New',Courier,monospace] t += exc.Message[/FONT]
  46. [FONT='Courier New',Courier,monospace] [/FONT]
  47. [FONT='Courier New',Courier,monospace] [/FONT]
  48. [FONT='Courier New',Courier,monospace] Finally [/FONT]
  49. [FONT='Courier New',Courier,monospace] conn.Close()[/FONT]
  50. [FONT='Courier New',Courier,monospace] [/FONT]
  51. [FONT='Courier New',Courier,monospace] End Try[/FONT]
  52. [FONT='Courier New',Courier,monospace] ausgabe = t[/FONT]
  53. [FONT='Courier New',Courier,monospace]End Sub[/FONT]
  54. [FONT='Courier New',Courier,monospace] [/FONT]
  55. [FONT='Courier New',Courier,monospace] End Sub[/FONT]
  56. [FONT='Courier New',Courier,monospace]End Class[/FONT]
  57. [FONT='Courier New',Courier,monospace] </script> </HEAD> <body> <FORM id="Form1" method="post" runat="server"> <H3>Verbindung mit Datenbank</H3> <P><asp:TextBox id="WO_NUM" runat="server"></asp:TextBox></P> <P><asp:TextBox id="Reqdate" runat="server"></asp:TextBox></P> <P><asp:TextBox id="Request" runat="server"></asp:TextBox></P> </FORM> </body> </HTML>[/FONT]
Hallo,

welchen Error bekommst du? Keinen? Dann vllt einmal in den Debugger jagen und schrittweise durchgehen.
 
Status
Für weitere Antworten geschlossen.
Zurück
Oben