ADO增删查改
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ADO增删查改相关的知识,希望对你有一定的参考价值。
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);
}
以上是关于ADO增删查改的主要内容,如果未能解决你的问题,请参考以下文章