עליך להתחבר בכדי להוריד קבצים מהאתר
על מנת להבטיח שמשאבינו לא ינוצלו לרעה.
1 : public class WebsiteDB
2 : {
3 : . . .
4 : public WebsiteDB()
5 : {
6 : . . .
7 : }
8 :
9 : public Websites SelectAll()
10 : {
11 : . . .
12 : }
13 : public Websites SelectByName(string name)
14 : {
15 : . . .
16 : }
17 : public Website SelectByID(string id)
18 : {
19 : . . .
20 : }
21 : private Websites Select()
22 : {
23 : . . .
24 : }
25 : private Websites CreateModel()
26 : {
27 : . . .
28 : }
29 :
30 : public int Insert(Website website)
31 : {
32 : StringBuilder sql_builder = new StringBuilder();
33 : sql_builder.AppendFormat("INSERT INTO Website (Name, LogoLink, Link) VALUES ('{0}','{1}', '{2}') ",
34 : website.Name, website.LogoLink, website.Link);
35 : return SaveChanges(sql_builder.ToString());
36 : }
37 : public int Update(Website website)
38 : {
39 : StringBuilder sql_builder = new StringBuilder();
40 : sql_builder.AppendFormat("UPDATE Website SET Name='{0}', LogoLink='{1}', Link ='{2}' WHERE WebsiteID = {3}",
41 : website.Name, website.LogoLink, website.Link, website.WebsiteID);
42 : return SaveChanges(sql_builder.ToString());
43 : }
44 : public int Delete(Website website)
45 : {
46 : StringBuilder sql_builder = new StringBuilder();
47 : sql_builder.AppendFormat("DELETE FROM Website WHERE WebsiteID = {0}", website.WebsiteID);
48 : return SaveChanges(sql_builder.ToString());
49 : }
50 : private int SaveChanges(string command_text)
51 : {
52 : int records = 0;
53 : try
54 : {
55 : command.CommandText = command_text;
56 : connection.Open();
57 : records = command.ExecuteNonQuery();
58 : }
59 : catch (Exception e)
60 : {
61 :
62 : }
63 : finally
64 : {
65 : connection.Close();
66 : }
67 : return records;
68 : }
69 : }
למאמר הבא: CRUD באמצעות ה- ORM |
חזרה לרשימת המאמרים |