1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Dim provider As DbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient") Dim results As DataTable = New DataTable() Using connection As DbConnection = provider.CreateConnection() connection.ConnectionString = "Data Source=VM-WIN7VS2K8PRO\SQLEXPRESS;Initial Catalog=AdventureWorksLT;Integrated Security=True" Dim command As DbCommand = connection.CreateCommand() command.CommandText = "SELECT * FROM [SalesLT].[Customer] WHERE [CustomerID]=@Id" command.CommandType = CommandType.Text Dim parameter As DbParameter = command.CreateParameter() parameter.DbType = DbType.String parameter.Direction = ParameterDirection.Input parameter.ParameterName = "@Id" parameter.Value = 1 command.Parameters.Add(parameter) connection.Open() results.Load(command.ExecuteReader(CommandBehavior.CloseConnection)) End Using For Each row As DataRow In results.Rows Console.WriteLine(String.Format("Id: {0}", row.Field(Of Integer)(0))) Next
George J.
Φίλε μου είναι καλή πρακτική εφόσον έχεις λάβει απάντηση που σε ικανοποιει να πατήσεις το κουμπί "σημειώση ως Απαντητής" , έτσι η ερώτηση σου αλλάζει κατάσταση και δεν εκκρεμεί.