2010-06-29 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / class / System.Data / Test / OdbcTest.cs
1 //\r
2 // OdbcTest.cs - Test for the ODBC ADO.NET Provider in System.Data.Odbc \r
3 //\r
4 // The test works on Windows XP using Microsoft .NET Framework 1.1 Beta\r
5 //\r
6 // To compile under Windows using Microsoft .NET 1.1\r
7 // E:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc OdbcTest.cs /reference:System.Data.dll\r
8 //\r
9 // To compile under Windows using Mono:\r
10 // mcs OdbcTest.cs -r System.Data.dll\r
11 //\r
12 // I have not tested it on Linux using unixODBC\r
13 //\r
14 // Author:\r
15 //     Daniel Morgan <danmorg@sc.rr.com>\r
16 //\r
17
18 //
19 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
20 //
21 // Permission is hereby granted, free of charge, to any person obtaining
22 // a copy of this software and associated documentation files (the
23 // "Software"), to deal in the Software without restriction, including
24 // without limitation the rights to use, copy, modify, merge, publish,
25 // distribute, sublicense, and/or sell copies of the Software, and to
26 // permit persons to whom the Software is furnished to do so, subject to
27 // the following conditions:
28 // 
29 // The above copyright notice and this permission notice shall be
30 // included in all copies or substantial portions of the Software.
31 // 
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 //
40 \r
41 using System;\r
42 using System.Data;\r
43 using System.Data.Odbc;\r
44 \r
45 namespace Test.OdbcTest\r
46 {\r
47         class OdbcTest\r
48         {\r
49                 [STAThread]\r
50                 static void Main(string[] args)\r
51                 {\r
52                         OdbcConnection dbcon = new OdbcConnection();\r
53                         // connection string to a Microsoft SQL Server 2000 database\r
54                         // that does not use a DSN\r
55                         //dbcon.ConnectionString = \r
56                         //      "DRIVER={SQL Server};" + \r
57                         //      "SERVER=(local);" + \r
58                         //      "Trusted_connection=true;" +\r
59                         //      "DATABASE=pubs;";\r
60 \r
61                         // connection string that uses a DSN.\r
62                         dbcon.ConnectionString = \r
63                                 "DSN=LocalServer;UID=sa;PWD=";\r
64                                 \r
65                         dbcon.Open();\r
66 \r
67                         OdbcCommand dbcmd = new OdbcCommand();\r
68                         dbcmd.Connection = dbcon;\r
69                         dbcmd.CommandType = CommandType.Text;\r
70                         dbcmd.CommandText = "SELECT lname FROM employee";\r
71                         \r
72                         OdbcDataReader reader;\r
73                         reader = (OdbcDataReader) dbcmd.ExecuteReader();\r
74 \r
75                         while(reader.Read()) {\r
76                                 Console.WriteLine("Last Name: " + reader[0].ToString());\r
77                         }\r
78                         reader.Close();\r
79                         dbcmd.Dispose();\r
80                         dbcon.Close();\r
81                 }\r
82         }\r
83 }\r