using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Web; using System.Web.Configuration; using System.Configuration; namespace DAL { public class cls_SQLFunction { string connectionString = ""; System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["K3ConnectionString"]; /// <summary> /// 读取数据库 /// </summary> /// <param name="ComTxt">数据库查询语句</param> /// <param name="TableName">表名</param> /// <returns>查询结果——数据集</returns> public DataSet Read_DataSet(string ComTxt, string TableName) { try { if (null != connString) { connectionString = connString.ConnectionString; } SqlConnection con; SqlCommand selectcmd; con = new SqlConnection(connectionString); con.Open(); selectcmd = new SqlCommand(); selectcmd.CommandText = ComTxt; selectcmd.CommandTimeout = 1800; SqlDataAdapter adapter = new SqlDataAdapter(selectcmd.CommandText, con); adapter.SelectCommand.CommandTimeout = 1800; DataSet ds = new DataSet(); adapter.Fill(ds, TableName); DataTable dt = ds.Tables[TableName]; con.Close(); return ds; } catch { DataSet ds = new DataSet(); ds = null; return ds; } } //-------------------------------------------------------------------------------- /// <summary> /// 插入、删除、修改数据库 /// </summary> /// <param name="ComTxt">SQL语句</param> public bool SQLUpdate(string ComTxt) { try { if (null != connString) { connectionString = connString.ConnectionString; } SqlConnection con; SqlCommand selectcmd; con = new SqlConnection(connectionString); con.Open(); selectcmd = new SqlCommand(); selectcmd.Connection = con; selectcmd.CommandText = ComTxt; //执行TSQL、表名、存储过程、一段SQL语句 selectcmd.ExecuteNonQuery(); con.Close(); return true; } catch { return false; } } //-------------------------------------------------------------------------------- /// <summary> /// 数据库二进制数据写入 /// </summary> /// <param name="ComTxt">SQL语句</param> /// <param name="File">文件二进制流</param> /// <returns>是否写入成功</returns> public bool SQLUpdate_Photo(string ComTxt, byte[] File) { try { if (null != connString) { connectionString = connString.ConnectionString; } SqlConnection con; SqlCommand selectcmd; con = new SqlConnection(connectionString); con.Open(); selectcmd = new SqlCommand(ComTxt, con); selectcmd.Parameters.Add("@File", SqlDbType.Image); selectcmd.Parameters[0].Value = File; selectcmd.ExecuteNonQuery(); con.Close(); return true; } catch { return false; } } } }