2009-12-01 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Mono.Data / DataTools.cs
blob9f830211380d337bd36687e64059707290917843
1 //
2 // Mono.Data.DataTools
3 //
4 // Authors:
5 // Brian Ritchie (brianlritchie@hotmail.com)
6 //
7 //
8 // Copyright (C) Brian Ritchie, 2002
9 //
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.
32 using System;
33 using System.Data;
35 namespace Mono.Data
37 /// <summary>
38 /// Summary description for ProviderTools.
39 /// </summary>
40 #if NET_2_0
41 [Obsolete("ProviderFactory in assembly Mono.Data has been made obsolete by DbProviderFactories in assembly System.Data.")]
42 #endif
43 public class DataTools
45 public DataTools()
49 static public IDataParameter AddParameter(IDbCommand Cmd, string ParameterName, DbType DbType,
50 ParameterDirection Direction)
52 if (Cmd == null)
53 throw new System.ArgumentNullException ("Cmd");
54 if (ParameterName == null)
55 throw new System.ArgumentNullException ("ParameterName");
57 IDataParameter param = Cmd.CreateParameter ();
58 Cmd.Parameters.Add (param);
59 param.ParameterName = ParameterName;
60 param.Direction = Direction;
61 param.DbType = DbType;
62 return param;
65 static public IDataParameter AddParameter(IDbCommand Cmd, string ParameterName, DbType DbType)
67 if (Cmd == null)
68 throw new System.ArgumentNullException ("Cmd");
69 if (ParameterName == null)
70 throw new System.ArgumentNullException("ParameterName");
72 IDataParameter param = Cmd.CreateParameter ();
73 Cmd.Parameters.Add (param);
74 param.ParameterName = ParameterName;
75 param.DbType = DbType;
76 return param;
79 static public DataSet FillDataSet (IDbConnection conn, string SelectCommand)
81 if (conn == null)
82 throw new System.ArgumentNullException ("conn");
83 if (SelectCommand == null)
84 throw new System.ArgumentNullException ("SelectCommand");
86 DataSet ds = new DataSet ();
87 IDbDataAdapter adapter = ProviderFactory.CreateDataAdapter (conn, SelectCommand);
88 if (conn.State != ConnectionState.Open)
89 conn.Open ();
90 adapter.Fill (ds);
91 return ds;
94 static public DataSet FillDataSet(IDbCommand SelectCommand)
96 if (SelectCommand == null)
97 throw new System.ArgumentNullException ("SelectCommand");
99 DataSet ds = new DataSet ();
100 IDbDataAdapter adapter = ProviderFactory.CreateDataAdapter (SelectCommand);
101 if (adapter.SelectCommand.Connection.State != ConnectionState.Open)
102 adapter.SelectCommand.Connection.Open ();
103 adapter.Fill (ds);
104 return ds;
107 static public DataSet FillDataSet(string ConfigSetting, string SelectCommand)
109 if (ConfigSetting == null)
110 throw new System.ArgumentNullException ("ConfigSetting");
111 if (SelectCommand == null)
112 throw new System.ArgumentNullException ("SelectCommand");
114 IDbConnection conn = ProviderFactory.CreateConnectionFromConfig (ConfigSetting);
115 conn.Open ();
116 DataSet ds = null;
119 ds = new DataSet ();
120 IDbDataAdapter adapter = ProviderFactory.CreateDataAdapter (conn, SelectCommand);
121 adapter.Fill (ds);
123 finally
125 conn.Close ();
127 return ds;