惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
WordPress大学
WordPress大学
爱范儿
爱范儿
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
博客园_首页
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
MyScale Blog
MyScale Blog
IT之家
IT之家
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

博客园 - 空军

过多边形边上某点的任意直线等分面积 VisualAPL Installer for Visual Studio 2008 [ZT] Create a Microsoft Access Database Using ADOX and Visual Basic .NET 数的分解,据说是清华的一道复试上机题 为System.Windows.Forms.FontDialog类添加Location属性 f(f(x)) = -x [zt]〖Math〗构造函数使得任意小的区间所对应的值域都是整个实数域 [zt]鸟巢、水立方:同一个地方,同一梦想 〖Math〗据传,任意锐角等于0° 爱因斯坦的超级问题(谁养鱼)SQL解法 “槑囧圐圙”您认得这些汉字吗? 根据URL提取页面的Title,根据网页的charset自动判断Encoding MSDN“MidpointRounding 枚举”中文翻译有误 C# 2.0 新特性(泛型、可空类型)应用一例 表达式计算器 Google速记 Google中国编程挑战赛第一轮 Google中国编程挑战赛资格赛 数学家
数据库访问模块
空军 · 2005-10-15 · via 博客园 - 空军

 1namespace Skyiv.Data.SqlClient
 2{
 3  using System.Data;
 4  using System.Data.SqlClient;
 5
 6  class SqlObject
 7  {
 8    protected SqlConnection conn;
 9
10    // 构造函数,参数为连接串。
11    protected SqlObject(string strConn)
12    {
13      conn = new SqlConnection(strConn);
14    }

15
16    // 执行SQL,将结果返回到数据集中。
17    public DataSet DsQuery(string strSql, params SqlParameter [] paras)
18    {
19      SqlCommand cmd = new SqlCommand(strSql, conn);
20      foreach (SqlParameter para in paras)
21      {
22        cmd.Parameters.Add(para);
23      }

24      SqlDataAdapter apt = new SqlDataAdapter(cmd);
25      DataSet ds = new DataSet();
26      apt.Fill(ds);
27      return ds;
28    }

29
30    // 执行SQL,将结果返回到数据表中。
31    public DataTable DtQuery(string strSql, params SqlParameter [] paras)
32    {
33      return DsQuery(strSql, paras).Tables[0];
34    }

35
36    // 执行SQL,将结果返回到数据行中。
37    public DataRow DrQuery(string strSql, params SqlParameter [] paras)
38    {
39      DataTable dt = DsQuery(strSql, paras).Tables[0];
40      if (dt.Rows.Count == 0return null;
41      else return dt.Rows[0];
42    }

43
44    // 执行SQL,并返回查询所返回的结果集中第一行的第一列。
45    public object ScalarQuery(string strSql, params SqlParameter [] paras)
46    {
47      SqlCommand cmd = new SqlCommand(strSql, conn);
48      try
49      {
50        cmd.Connection.Open();
51        foreach (SqlParameter para in paras)
52        {
53          cmd.Parameters.Add(para);
54        }

55        return cmd.ExecuteScalar();
56      }

57      finally
58      {
59        cmd.Connection.Close();
60      }

61    }

62
63    // 执行SQL,返回受影响的行数。
64    public int ExecNonQuery(string strSql, params SqlParameter [] paras)
65    {
66      SqlCommand cmd = new SqlCommand(strSql, conn);
67      cmd.Connection.Open();
68      foreach (SqlParameter para in paras)
69      {
70        cmd.Parameters.Add(para);
71      }

72      int n = cmd.ExecuteNonQuery();
73      cmd.Connection.Close();
74      return n;
75    }

76
77    // 执行SQLs,返回受影响的行数。
78    public int ExecNonQuerys(params string [] strSqls)
79    {
80      SqlCommand cmd = new SqlCommand();
81      cmd.Connection = conn;
82      cmd.Connection.Open();
83      int n = 0;
84      foreach (string strSql in strSqls)
85      {
86        cmd.CommandText = strSql;
87        n += cmd.ExecuteNonQuery();
88      }

89      cmd.Connection.Close();
90      return n;
91    }

92
93  }
 // End of class SqlObject
94}
   // End of namespace Skyiv.Data.Sql