Connection C# & sql server 2005
Résolu/Fermé
feros2184
Messages postés
10
Date d'inscription
mercredi 19 novembre 2008
Statut
Membre
Dernière intervention
20 avril 2010
-
6 févr. 2009 à 10:16
snk111 - 29 déc. 2010 à 04:05
snk111 - 29 déc. 2010 à 04:05
A voir également:
- Connection C# & sql server 2005
- Télécharger money 2005 - Télécharger - Comptabilité & Facturation
- Gmail connection - Guide
- Ps3 media server - Télécharger - Divers Réseau & Wi-Fi
- Filezilla server - Télécharger - Téléchargement & Transfert
- Mysql community server - Télécharger - Bases de données
5 réponses
Melooo
Messages postés
1405
Date d'inscription
vendredi 28 novembre 2008
Statut
Membre
Dernière intervention
18 mars 2013
84
6 févr. 2009 à 11:06
6 févr. 2009 à 11:06
Je me trompe peut etre mais OleDBConnection c'est pas pour une base de donnée Access ? Pour une base de donnée SQL Server c'est SqlConnection je crois.
To connect to SQL Server from C#.NET, you need to create a connection string such as below:
private SqlConnection connection;
private string connectionString =
@"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123";
connection = new SqlConnection( connectionString );
Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);
The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.
Next to execute the SQL queries in the database, you use the following methods:
ExecuteReader - to execute SELECT queries
ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.
This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
For details about the connection string, the methods and their parameters check the following link: ( https://www.shahriarnk.com/ )
Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.
private SqlConnection connection;
private string connectionString =
@"Server=(local);Database=Embedding_SQL_Test;User ID=sa;Password=123";
connection = new SqlConnection( connectionString );
Next, you use the SqlConnection object created above to create a 'SqlCommand', as shown below:
SqlCommand cmd = new SqlCommand( "select * from Customer where CustomerID = @Cid", connection);
The SQL query shown here can be replaced by a SELECT, INSERT, UPDATE queries etc.
Next to execute the SQL queries in the database, you use the following methods:
ExecuteReader - to execute SELECT queries
ExecuteNonQuery - to execute INSERT, DELETE, UPDATE, and SET statements.
This is a very short description of how to connect to SQL Server database from C# and execute SQL queries in the database.
For details about the connection string, the methods and their parameters check the following link: ( https://www.shahriarnk.com/ )
Here you will also find details about how to pass parameters to the SQL queries as well as calling stored procedures and much more.
Melooo
Messages postés
1405
Date d'inscription
vendredi 28 novembre 2008
Statut
Membre
Dernière intervention
18 mars 2013
84
6 févr. 2009 à 10:21
6 févr. 2009 à 10:21
Bonjour,
Jettez un oeil la dessus : https://www.connectionstrings.com/
Jettez un oeil la dessus : https://www.connectionstrings.com/
feros2184
Messages postés
10
Date d'inscription
mercredi 19 novembre 2008
Statut
Membre
Dernière intervention
20 avril 2010
6 févr. 2009 à 10:40
6 févr. 2009 à 10:40
Merci Melooo pour votre reponse,
j'ai deja cherché sur ce site mais j'ai pas arrivé a trouvé la solution...
toujours il m'affiche:
j'ai deja cherché sur ce site mais j'ai pas arrivé a trouvé la solution...
toujours il m'affiche:
Spécification de permission non valide Attribut de chaîne de connexion non valide
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
feros2184
Messages postés
10
Date d'inscription
mercredi 19 novembre 2008
Statut
Membre
Dernière intervention
20 avril 2010
7 févr. 2009 à 02:07
7 févr. 2009 à 02:07
Merci à tous
j'ai trouver la solution...
j'ai trouver la solution...
OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=SQLOLEDB;Driver={SQL Native Client};Server=SERT\\SQLEXPRESS;Database=client;Trusted_Connection=yes;"; try { conn.Open(); MessageBox.Show("Base de données ouverte...."); // Insert code to process data. } catch (Exception ex) { MessageBox.Show(ex.ToString()); }