DBexec.cs
上传用户:fzwcsgshou
上传日期:2022-07-30
资源大小:28414k
文件大小:2k
源码类别:

行业应用

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. namespace KTVData
  7. {
  8.     class DBexec
  9.     {
  10.         public static bool exec(string command)
  11.         {
  12.             bool tag = false;
  13.             SqlConnection conn = new SqlConnection(ConfigClass.configValue);
  14.             SqlCommand cmd = new SqlCommand(command, conn);
  15.             try
  16.             {
  17.                 conn.Open();
  18.                 if (cmd.ExecuteNonQuery() > 0)
  19.                 {
  20.                     tag = true;
  21.                 }
  22.             }
  23.             catch
  24.             {
  25.                 tag = false;
  26.             }
  27.             finally
  28.             {
  29.                 cmd.Dispose();
  30.                 conn.Dispose();
  31.                 conn.Close();
  32.             }
  33.             return tag;
  34.         }
  35.         public static DataSet Select(string command)
  36.         {
  37.             SqlDataAdapter adpt = new SqlDataAdapter(command, ConfigClass.configValue);
  38.             DataSet ds = new DataSet();
  39.             adpt.Fill(ds);
  40.             return ds;
  41.         }
  42.         public static int exec(string command, int i)
  43.         {
  44.             int tag = 0;
  45.             
  46.             SqlConnection conn = new SqlConnection(ConfigClass.configValue);
  47.             SqlCommand cmd = new SqlCommand(command, conn);
  48.             try
  49.             {
  50.                 conn.Open();
  51.                 tag = cmd.ExecuteNonQuery();
  52.             }
  53.             catch
  54.             {
  55.                 tag = -1;
  56.             }
  57.             finally
  58.             {
  59.                 cmd.Dispose();
  60.                 conn.Dispose();
  61.                 conn.Close();
  62.             }
  63.             return tag;
  64.         }
  65.     }
  66. }