Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
bases_programmation:acces_aux_bases_de_donnees_sgbdr [2017/08/08 08:27] admin |
bases_programmation:acces_aux_bases_de_donnees_sgbdr [2017/08/08 08:39] (Version actuelle) admin [Connexion ODBC] |
||
|---|---|---|---|
| Ligne 89: | Ligne 89: | ||
| <code> | <code> | ||
| - | public void CreateOdbcConnection() | + | using System.Data; |
| - | { | + | using Microsoft.Data.Odbc; |
| - | string myConnString = "DRIVER={SQL Server Native Client 11.0};SERVER=srvsql;Trusted_connection=yes;DATABASE=NemoGrp1;"; | + | |
| - | System.Data.Odbc.OdbcConnection myConnection = new System.Data.Odbc.OdbcConnection(myConnString); | + | string myConnectionString = ""Driver={SQL Server};Server=mySQLServer;UID=***;PWD=***;Database=***;""; |
| - | myConnection.Open(); | + | string mySelectQuery = "Select * from Client"; |
| - | System.Data.Odbc.OdbcCommand command = myConnection.CreateCommand(); | + | public void CreateMyOdbcDataReader(string mySelectQuery,string myConnectionString) |
| - | command.CommandText = "Select * from CLIENT"; | + | { |
| - | System.Data.Odbc.OdbcDataReader reader = command.ExecuteReader(); | + | OdbcConnection myConnection = new OdbcConnection(myConnectionString); |
| - | reader.Read(); | + | OdbcCommand myCommand = new OdbcCommand(mySelectQuery, myConnection); |
| - | String str = reader.GetString(0) +" "+ reader.GetString(1) +" "+ reader.GetString(2); | + | myConnection.Open(); |
| - | MessageBox.Show("Resultat : " + str); | + | OdbcDataReader myReader = myCommand.ExecuteReader(); |
| - | + | try | |
| - | myConnection.Close(); | + | { |
| + | while(myReader.Read()) | ||
| + | { | ||
| + | Console.WriteLine(myReader.GetString(0)); | ||
| + | } | ||
| + | } | ||
| + | finally | ||
| + | { | ||
| + | myReader.Close(); | ||
| + | myConnection.Close(); | ||
| + | } | ||
| + | } | ||
| } | } | ||
| </code> | </code> | ||
| + | <WRAP center round tip 60%> | ||
| + | Il faut télécharger le fournisseur managé ODBC .NET sur le site Web de Microsoft à l’adresse suivante : | ||
| + | http://www.microsoft.com/downloads/details.aspx?familyid=6ccd8427-1017-4f33-a062-d165078e32b1 | ||
| + | </WRAP> | ||
| + | |||