-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetData.cs
More file actions
90 lines (82 loc) · 2.23 KB
/
GetData.cs
File metadata and controls
90 lines (82 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GetData
{
// Change this connection string your need.
// private const string connectionString = @"server=.;database=MonitorDemo2;uid=sa;pwd=sa";
//private const string connectionString = @"Data Source=LOCALHOST;Initial Catalog=AdventureWorks;Integrated Security=True;";
[OperationContract]
public DataSetData GetDataSetData(string ConnStr,string SQL, out CustomException ServiceError)
{
try
{
DataSet ds = GetDataSet(ConnStr,SQL);
ServiceError = null;
return DataSetData.FromDataSet(ds);
}
catch(Exception ex)
{
ServiceError = new CustomException(ex);
}
return null;
}
//[OperationContract]
//public bool Update(DataSetData d, out CustomException ServiceError)
//{
// try
// {
// DataSet ds = DataSetData.ToDataSet(d);
// UpdataDataSet(ds);
// ServiceError = null;
// return true;
// }
// catch(Exception ex)
// {
// ServiceError = new CustomException(ex);
// }
// return false;
//}
//private void UpdataDataSet(DataSet ds)
//{
// try
// {
// //You need to Implement UpdataDataSet the way you want it.
// }
// catch (Exception e)
// {
// throw new Exception("Update DataSata Failed", e);
// }
//}
private DataSet GetDataSet(string connectionString,string SQL)
{
DataSet ds;
SqlConnection Connection = new SqlConnection(connectionString);
try
{
Connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(SQL);
adapter.SelectCommand.Connection = Connection;
ds = new DataSet();
adapter.Fill(ds);
}
catch (Exception err)
{
throw err;
}
finally
{
Connection.Close();
}
return ds;
}
}