C#:Read From a Database
From Progzoo
Top Ten Tips
Read Database
The .Net framework includes several "parallel" namespaces that connect you to a database.
System.Data.SqlClient connects to Microsoft's own database SQL Server; alternatives include
System.Data.Odbc and System.Data.OleDb and System.Data.OracleClient
[edit] Read from a SQL Server database
To read from a SQL Server database you can use the classes in System.Data.SqlClient
- SqlCommand
- SqlConnection
- SqlDataReader
| value | description |
|---|---|
| 127.0.0.1 | the IP address database server; |
| gisq | the name of the database; |
| scott | user name; |
| tiger | the password; |
Read the name and population for each country with a population of more than 200000000.
The SQL statement is:
SELECT name, population FROM bbc WHERE population>200000000
The table bbc has columns:
- name
- region
- area
- population
- gdp
[Font]
[Default]
[Show]
[Resize]