Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Datenbankverbindung macht Probleme

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

ich möchte einen Datenbankzugriff auf eine Ms SQL Server 2005 DB herstellen und bekomme dabei ständig eine Fehlermeldung, mit der ich nichts anfangen kann. Genauer gesagt tritt der Fehler beim verwenden der Fill-Funktion der DataTable auf. Kann mir jemand sagen, woran das liegen kann?

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        'Connection zur Datenbank herstellen

        Dim con As DbConnection = New SqlConnection()

        con.ConnectionString = "Data Source = xxx; Initial Catalog=xxx ; User Id = xxx ; Pwd = xxx"


        'Übergabe des SQL-Statements an DBCommand

        Dim cmd As DbCommand = New SqlCommand()

        cmd.CommandText = "Select * from DW-Artikel"

        cmd.Connection = con


        'Dataadapter

        Dim da As DbDataAdapter = New SqlDataAdapter()

        da.SelectCommand = cmd


        Dim tbl As New DataTable()

        da.Fill(tbl)

Beste Grüße

Noobvb.net

kopiere doch bitte mal den fehler und poste ihn mal.

also der typ db ist mir gänzlich unbekannt. Meines wissen benutzt man für eine sql server DB einen sqlclient.

probiers doch mal mit folgendem code:


Dim con As New Data.SqlClient.SqlConnection("Data Source=IP; " & "Initial Catalog=DBname;" & "User ID=user;" & "Pwd=pwd")


 Dim cmd As New SqlClient.SqlCommand

            cmd.Connection = con

            cmd.CommandText = "Select * From mytable (als beispielabfrage)"

            Dim ds As New DataSet

            Dim data1 As New SqlClient.SqlDataAdapter(cmd)

            data1.Fill(ds)

            DataGridView1.DataSource = ds.Tables(0)



lg

simon

Hi Simon,

vielen Dank für deine Hilfe.

Da ich keine Ahnung hatte, wie ich in vb.net eine DB Verbindung herstelle, habe ich gegooglet und da hab ich eben in einem Ebook diesen Weg gefunden. Deshalb der Typ DBConnect. Der Fehler tritt bei der Fill-Funktion auf. Dort steht dann: "Fehler in der Nähe von "-" entdeckt".

Gruß

Manuel

Fehler in der Nähe von "-" entdeckt

"Select * from DW-Artikel"

in tabellennamen dürfen keine rechenzeichen vorkommen, es sei denn erstere werden in klammern gesetzt.

weiters würde ich mir angewöhnen, in connectstrings leerzeichen nach semikolons rauszulassen.

s'Amstel

Hi Leute,

vielen Dank für eure Hilfe.

Es haben nur ein paar eckige Klammern gefehlt. Wäre nie drauf gekommen, dass das am Tabellenname liegen könnte. Vielen Dank nochmal.

Gruß

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.