1
13693261870
2024-04-26 889ada155e457dbc703531f9628353d288ca3f92
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
 
namespace Terra.YaoGan.Common
{
    public sealed class sqlserverHelper : IDatabaseInterface
    {
        private static readonly object lk = new object();
        private SqlConnection con = null;
        private static sqlserverHelper db = null;
        private string cstr = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
 
        #region  数据库连接
        public static sqlserverHelper  getInstance()
        {
            if (db == null)
            {
                lock (lk)
                {
                    if (db == null)
                    {
                        db = new sqlserverHelper();
                    }
                }
            }          
            return db;
        }
        
        public void connect()
        {
            try
            {
                con = new SqlConnection(cstr);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
            }
            catch (Exception e)
            {
 
            }
        }
        
        public void close()
        {
            try
            {
                if (con != null)
                {
                    con.Dispose();
                    con.Close();
                }
            } catch(Exception e)
            {
 
            }
        }
 
        public int getRow(string sql)
        {
 
            int result = -1;
            try
            {
                connect();
                result = new SqlCommand(sql, con).ExecuteNonQuery();
                close();
            }
            catch(Exception e)
            {
                close();
            }
            
            return result;
        }
 
        public DataTable QuerySql(string sql)
        {
            DataTable dt = new DataTable();
            try
            {
                connect();
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                sda.Fill(dt);
                close();
            }
            catch(Exception e)
            {
                close();
            }
            
            return dt;
        }
 
 
 
 
 
 
        #endregion
 
 
 
 
    }
}