2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Data / DataTools.cs
1 //\r
2 // Mono.Data.DataTools\r
3 //\r
4 // Authors:\r
5 //   Brian Ritchie (brianlritchie@hotmail.com) \r
6 //  \r
7 //\r
8 // Copyright (C) Brian Ritchie, 2002\r
9 // \r
10 //\r
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 using System;\r
33 using System.Data;\r
34 \r
35 namespace Mono.Data\r
36 {\r
37         /// <summary>\r
38         /// Summary description for ProviderTools.\r
39         /// </summary>\r
40         public class DataTools\r
41         {\r
42                 public DataTools()\r
43                 {\r
44                 }\r
45 \r
46                 static public IDataParameter AddParameter(IDbCommand Cmd, string ParameterName, DbType DbType, \r
47                         ParameterDirection Direction)\r
48                 {\r
49                         IDataParameter param=Cmd.CreateParameter();\r
50                         Cmd.Parameters.Add(param);\r
51                         param.ParameterName=ParameterName;\r
52                         param.Direction=Direction;\r
53                         param.DbType=DbType;\r
54                         return param;\r
55                 }\r
56 \r
57                 static public IDataParameter AddParameter(IDbCommand Cmd, string ParameterName, DbType DbType)\r
58                 {\r
59                         IDataParameter param=Cmd.CreateParameter();\r
60                         Cmd.Parameters.Add(param);\r
61                         param.ParameterName=ParameterName;\r
62                         param.DbType=DbType;\r
63                         return param;\r
64                 }\r
65 \r
66                 static public DataSet FillDataSet(IDbConnection conn, string SelectCommand)\r
67                 {\r
68                         DataSet ds=new DataSet();\r
69                         IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(conn, SelectCommand);\r
70                         if (conn.State!=ConnectionState.Open)\r
71                                 conn.Open();\r
72                         adapter.Fill(ds);\r
73                         return ds;\r
74                 }\r
75 \r
76                 static public DataSet FillDataSet(IDbCommand SelectCommand)\r
77                 {\r
78                         DataSet ds=new DataSet();\r
79                         IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(SelectCommand);\r
80                         if (adapter.SelectCommand.Connection.State!=ConnectionState.Open)\r
81                                 adapter.SelectCommand.Connection.Open();\r
82                         adapter.Fill(ds);\r
83                         return ds;\r
84                 }\r
85 \r
86                 static public DataSet FillDataSet(string ConfigSetting, string SelectCommand)\r
87                 {\r
88                         IDbConnection conn=ProviderFactory.CreateConnectionFromConfig(ConfigSetting);\r
89                         conn.Open();\r
90                         DataSet ds=null;\r
91                         try\r
92                         {\r
93                                 ds=new DataSet();\r
94                                 IDbDataAdapter adapter=ProviderFactory.CreateDataAdapter(conn, SelectCommand);\r
95                                 adapter.Fill(ds);\r
96                         }\r
97                         finally\r
98                         {\r
99                                 conn.Close();\r
100                         }\r
101                         return ds;\r
102                 }\r
103 \r
104 \r
105         }\r
106 }\r