Hej Arne. Nu har jeg kigget på din kode, den ser jo dejlig simpel ud.
Men får dog stadig fejlmeddelser når jeg prøver at kompile! Kan heller ikke forstå når jeg laver en console app så starter koden med Module, og det har du ikke med i dit eksempel?
Får disse fejl:
Error 1 'Sub Main' was not found in 'ConsoleApplication1.Module1'. Error 2 Statement cannot appear outside of a method body. 1 1 ConsoleApplication1 Error 3 Statement cannot appear outside of a method body. 2 1 ConsoleApplication1 Error 4 Statement cannot appear outside of a method body. 3 1 ConsoleApplication1 Error 5 'Class' statement must end with a matching 'End Class'. 5 1 ConsoleApplication1 Error 6 Syntax error. 6 1 ConsoleApplication1 Error 7 'Static' is not valid on a member variable declaration. 7 12 ConsoleApplication1 Error 8 End of statement expected. 7 24 ConsoleApplication1 Error 9 Syntax error. 8 5 ConsoleApplication1 Error 10 Declaration expected. 9 9 ConsoleApplication1 Error 11 Declaration expected. 10 9 ConsoleApplication1 Error 12 Declaration expected. 11 9 ConsoleApplication1 Error 13 Declaration expected. 12 9 ConsoleApplication1 Error 14 Statement cannot appear outside of a method body. 13 9 ConsoleApplication1 Error 15 Syntax error. 14 9 ConsoleApplication1 Error 16 Declaration expected. 15 13 ConsoleApplication1 Error 17 Syntax error. 16 9 ConsoleApplication1 Error 18 Declaration expected. 17 9 ConsoleApplication1 Error 19 Declaration expected. 18 9 ConsoleApplication1 Error 20 Syntax error. 19 5 ConsoleApplication1 Error 21 Syntax error. 20 1 ConsoleApplication1
Imports System Imports System.Data Imports System.Data.SqlClient
Class MainClass Public Shared Sub Main(ByVal args As String()) Dim con As SqlConnection = New SqlConnection("server=ARNEPC2;Integrated Security=SSPI;database=Test") con.Open Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM T1", con) Dim rdr As SqlDataReader = cmd.ExecuteReader While rdr.Read Console.WriteLine(rdr(0) & " " & rdr(1)) End While rdr.Close con.Close End Sub End Class
normalt angiver man med SQLServer PC navn og ikke localhost
integrated security er en feature i SQLServer hvor den bruger dit windows login til at logge dig i databasen (og derfor skal man ikke angive username og password)
hvis det er MySQL saa vil du angive localhost og brugernavn/password
Imports System Imports System.Data Imports MySql.Data.MySqlClient
Class MainClass Public Shared Sub Main(ByVal args As String()) Dim con As MySqlConnection = New MySqlConnection ("Database=Test;Data So urce=localhost;User Id=;Password=") con.Open Dim sel As MySqlCommand = New MySqlCommand ("SELECT * FROM T1", con) Dim rdr As MySqlDataReader = sel.ExecuteReader While rdr.Read Dim f1 As Integer = rdr(0) Dim f2 As String = rdr(1) Console.WriteLine(f1 & " " & f2) End While rdr.Close con.Close End Sub End Class
Tror ikke jeg har det installeret, for får disse fejl:
Error 1 'Sub Main' was not found in 'ConsoleApplication1.Module1'. Warning 2 Namespace or type specified in the Imports 'MySql.Data.MySqlClient' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. 3 9 ConsoleApplication1 Error 3 String constants must end with a double quote. 7 59 ConsoleApplication1 Error 4 Name 'urce' is not declared. 8 1 ConsoleApplication1 Error 5 Name 'localhost' is not declared. 8 6 ConsoleApplication1 Error 6 Character is not valid. 8 15 ConsoleApplication1 Error 7 Name 'con' is not declared. 9 9 ConsoleApplication1 Error 8 Type 'MySqlCommand' is not defined. 10 20 ConsoleApplication1 Error 9 Type 'MySqlDataReader' is not defined. 11 20 ConsoleApplication1 Error 10 Name 'con' is not declared. 18 9 ConsoleApplication1
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.