日期:2014-05-17 浏览次数:20428 次
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.SqlClient; using System.Data; /// <summary> ///SQLHELPER 的摘要说明 /// </summary> public class SQLHELPER { public static string connstr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"; public static void runsql(string sqltext,string returntype,params SqlParameter[] p) { SqlConnection conn = new SqlConnection(connstr); conn.Open(); SqlCommand comm = conn.CreateCommand(); comm.CommandText = sqltext; foreach(SqlParameter ps in p) { comm.Parameters.Add(ps); } switch (returntype) { case "dr": SqlDataReader dr = comm.ExecuteReader(); return dr; break; case "dt": SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); da.Fill(dt); conn.Close(); return dt; break; default: comm.ExecuteNonQuery(); conn.Close(); break; } } }