接口在ADO.NET中的应用(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:25 点击:次
7
8 namespace IFADO
9
10 {
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
16 string privider = ConfigurationManager.ConnectionStrings["conStr"].ProviderName;
17 IDbConnection conn;
18 switch (privider)
19 {
20 case "Access": conn = new OleDbConnection(conStr); break;
21
22 case "SQLSever": conn = new SqlConnection(conStr); break;
23
24 case "Oracle": conn = new OracleConnection(conStr); break;
25
26 default: throw new Exception("未找到合适的数据库,请扩展!);
27 }
28 using(conn)
29
30 {
31 conn.Open();
32 using (IDbCommand cmd = conn.CreateCommand())
33 {
34 cmd.CommandText = "SELECT * FROM Test_TableORDER BY Test_Table.ID DESC";
35
36 cmd.ExecuteNonQuery();
37 }
38 Console.WriteLine("完成查询!");
39
40 Console.ReadKey();
41 }
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>