InterviewSolution
| 1. |
How To Get Records From A Database? |
|
Answer» You have to get the "dot net driver" of the database (or any other DataSource) you want to ACCESS to. For example: Mysql: Connector/Net Access: Microsoft Access Driver Oracle: Oracle Data Access COMPONENTS (ODAC) Afterwards you build a connection STRING to tell your Program which driver you want to use and where the dataSource can be found. for example: Public const string DB_CONN_STRING = "Driver={Microsoft Access Driver (*.mdb)}; "+ "DBQ=D: CSTestDbReadWriteSimpleTest.mdb"; Afterwards you just have to open a connection to the database using the previously created connection string and send a query to the database to get the RECORD: ADO Connection conn = new ADO Connection (DB_CONN_STRING); Conn. Open (); ADODataReader dr; ADO Command cmd = new ADO Command ( "SELECT * FROM ", Conn); Cmd. Execute (out dr); while (dr.Read()){ ....} You have to get the "dot net driver" of the database (or any other DataSource) you want to access to. For example: Mysql: Connector/Net Access: Microsoft Access Driver Oracle: Oracle Data Access Components (ODAC) Afterwards you build a connection string to tell your Program which driver you want to use and where the dataSource can be found. for example: Public const string DB_CONN_STRING = "Driver={Microsoft Access Driver (*.mdb)}; "+ "DBQ=D: CSTestDbReadWriteSimpleTest.mdb"; Afterwards you just have to open a connection to the database using the previously created connection string and send a query to the database to get the record: ADO Connection conn = new ADO Connection (DB_CONN_STRING); Conn. Open (); ADODataReader dr; ADO Command cmd = new ADO Command ( "SELECT * FROM ", Conn); Cmd. Execute (out dr); while (dr.Read()){ ....} |
|