-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataService.cs
84 lines (74 loc) · 2.55 KB
/
DataService.cs
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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace AppForCloud
{
public class DataService
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlDataAdapter da;
SqlCommand cmd;
DataTable dt;
#region ManageUserInfo
public void InsertNewUser(PropertyService P)
{
cmd = new SqlCommand("InsertNewUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Fname", P.FirstName);
cmd.Parameters.AddWithValue("@Lname", P.LastName);
con.Open();
cmd.ExecuteNonQuery();//To Save Changes into Table. & to findout Number of affected by Query
con.Close();
}
public DataTable GetAllUsers()
{
da = new SqlDataAdapter("GetAllUsers", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
dt = new DataTable();
da.Fill(dt);
return dt;
}
public void UpdateUser(PropertyService P)
{
cmd = new SqlCommand("UpdateUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UID", P.UserID);
cmd.Parameters.AddWithValue("@Fname", P.FirstName);
cmd.Parameters.AddWithValue("@Lname", P.LastName);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public void DeleteUser(int UserID)
{
cmd = new SqlCommand("DeleteUser", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UID", UserID);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
#endregion
public DataTable GetAllStates()
{
da = new SqlDataAdapter("GetAllStates", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetCityByState(int StateID)
{
da = new SqlDataAdapter("GetCityByState", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@SID", StateID);
dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}