日期:2014-05-16 浏览次数:20945 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace 挂号系统
{
/// <summary>
/// 所有连接数据库的方式
/// </summary>
class SQLHelper
{
static string connStr = "server=.;database=PatientsDB;uid=sa;pwd=123456";
//增删改
#region
/// <summary>
/// 执行增删改语句
/// </summary>
/// <param name="sql">insert/delelt/update语句</param>
/// <param name="parameters">参数的数组</param>
/// <returns></returns>
public static int ExecuteNonQuery(string sql,params SqlParameter[] parameters)
{
//创建连接对象
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
//创建命令对象
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(parameters);
//返还受影响的行数
int row = cmd.ExecuteNonQuery();
conn.Close();
return row;
}
#endregion
//单行单列查询
#region
/// <summary>
/// 单行单列查询
/// </summary>
/// <param name="sql">select语句</param>
/// <param name="parameters">参数数组</param>
/// <returns>第一列第一行的内容</returns>
public static object ExecuteScalar(string sql, params SqlParameter[] parameters)
{
//创建连接对象
SqlConnection conn = new SqlConnection(connStr);
&n