标签:pen 读取 阅读器 and ati 数列 lda ring 数据库
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace SQLDB
{
public class SqlHelper
{
/// <summary>
/// 执行数据库操作(增删改)
/// </summary>
/// <param name="constr">连接字符串</param>
/// <param name="cmdstr">操作字符串(增删改)</param>
/// <param name="ps">参数列表</param>
/// <returns>返回受影响行数</returns>
public static int ExecuteNonQuery(string constr,string cmdstr,params SqlParameter[] ps)
{
SqlConnection conn = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(cmdstr, conn);
if (ps != null)
{
cmd.Parameters.AddRange(ps);
}
conn.Open();
int i = cmd.ExecuteNonQuery();
conn.Close();
return i;
}
/// <summary>
/// 执行查询操作(需要手动读取)
/// </summary>
/// <param name="constr">连接语句</param>
/// <param name="cmdstr">执行语句</param>
/// <param name="ps">参数列表</param>
/// <returns>返回数据阅读器</returns>
public static SqlDataReader ExecuteDataReader(string constr,string cmdstr,params SqlParameter[] ps)
{
SqlConnection conn = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(cmdstr, conn);
if (ps != null)
{
cmd.Parameters.AddRange(ps);
}
标签:pen 读取 阅读器 and ati 数列 lda ring 数据库
原文地址:http://www.cnblogs.com/bingsying/p/7850722.html