日期:2014-05-17  浏览次数:20855 次

C# SqlParameter问题
在WinForm和WebForm里面我都是在项目里面创建一个操作类,如下:

using System;

using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace SmartSql
{
    public class Helper
    {
        private SqlConnection connection;
        public SqlConnection Connection
        {
            get
            {
                string connectionString = "server=;database=;uid=;pwd=";
                if (connection == null)
                {
                    connection = new SqlConnection(connectionString);
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Broken)
                {
                    connection.Close();
                    connection.Open();
                }
                return connection;
            }
        }

  /// <summary>
        /// 执行SQL语句,返回受影响的行数。
        /// </summary>
        /// <param name="safeSql">执行的SQL语句</param>
        /// <returns></returns>
        public int ExecuteCommand(string safeSql)
        {
            using (SqlConnection con = Connection)
            {