Announcement

Collapse
No announcement yet.

MySQL + VbExpress Tabellen zur Laufzeit anlegen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL + VbExpress Tabellen zur Laufzeit anlegen

    Hi,
    Im Grunde habe ich eigentlich 2 Fragen:
    1. wie oben und 2. lesbare Tutorials (einfache Beispiele vom Anlegen, Datenmanipulationen bis hin zur Ausgabe der Daten in Textfiles), weil ich zwischenzeitig insges. 4 Bücher (Koffler und Markt&Technik) zu diesem Thema gekauft habe und mir letztendlich nicht wirklich das "Licht aufgegangen" ist. Mit VB6 habe ich mich "grob" ausgekannt, bin aber kein "Experte". Wikipedia, Google etc. haben auch nichts brauchbares gebracht.
    Vielleicht kann mir jemand diesbezüglich helfen.
    Zur Frage 1.:
    Ich bekomme zwar die Meldung:"Tabelle erfolgreich angelegt", tatsächlich ist nichts geschehen. Was mache ich da falsch?
    Code:
        Dim myconn As MySqlConnection
        myconn = New MySqlConnection( _
        "Data Source=localhost; Initial Catalog=stammdaten; User ID=root;PWD=xxxxxxx")
        myconn.Open()
    
        Dim cmd As MySqlCommand
        Try
          cmd = New MySqlCommand("USE stammdaten" & _
                "DROP TABLE IF EXISTS MaxWerte45" & _
                "USE stammdaten" & _
                "CREATE TABLE MaxWerte45(" & _
                "Datum date, " & _
                "Z1 TINYINT, " & _
                "Z2 TINYINT, " & _
                "Z3 TINYINT, " & _
                "Z4 TINYINT, " & _
                "Z5 TINYINT, " & _
                "Z6 TINYINT, " & _
                "Z7 TINYINT, " & _
                "Z8 TINYINT, " & _
                "ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " & _
                "Hit VARCHAR(7), " & _
                "ENGINE = MyISAM, " & _
                "DEFAULT CHARSET = latin1, " & _
                "COLLATE = latin1_german1_ci")
    
          MessageBox.Show("Tabelle 'MaxWerte45' successfully created.", _
              "Table Creation Status", _
              MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch sqlExc As SqlException
          MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
              MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        myconn.Close()
    Wenn ich mit diesem Skript diese Tabelle im Browser anlegen will, dann meckert der Compiler.
    Script line: 1 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"USE stammdaten" & _
    "DROP TABLE IF EXISTS MaxWerte45" & _
    ' at line 1
    Danke!

    Es war ziemlich zeitintensiv und leider auch ärgerlich....
    Trotzdem habe ich die Lösung gefunden.
    Dim sqlConn As MySqlConnection
    sqlConn = New MySqlConnection( _
    "Data Source=localhost; Initial Catalog=base; User ID=root;PWD=xxxxxx")
    Dim nonqueryCommand As MySqlCommand = sqlConn.CreateCommand()
    Try
    sqlConn.Open()
    nonqueryCommand.CommandText = "USE base; " & _
    "DROP table if exists `tblNN`; " & _
    "CREATE table `tblNN` (" & vbCrLf & _
    "Datum DATE," & vbCrLf & _
    "Z1 TINYINT(2)," & vbCrLf & _
    "Z2 TINYINT(2)," & vbCrLf & _
    "Z3 TINYINT(2)," & vbCrLf & _
    "Z4 TINYINT(2)," & vbCrLf & _
    "Z5 TINYINT(2)," & vbCrLf & _
    "Z6 TINYINT(2)," & vbCrLf & _
    "ID INT NOT NULL AUTO_INCREMENT, " & vbCrLf & _
    "PRIMARY KEY (`ID`), " & vbCrLf & _
    "Hit VARCHAR(3))" & vbCrLf & _
    "ENGINE = MyISAM " & vbCrLf & _
    "DEFAULT CHARSET = latin1 " & vbCrLf & _
    "COLLATE = latin1_german1_ci;"
    nonqueryCommand.ExecuteNonQuery()
    MessageBox.Show("Tabelle 'tblNN' erfolgreich erstellt", _
    Table Creation Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Catch sqlExc As MySqlException
    MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
    MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    sqlConn.Close()
    Grüße
    Zuletzt editiert von CarpeDiem; 02.08.2007, 13:23. Reason: Lösung gefunden...
Working...
X