注册 登录
编程论坛 ASP.NET技术论坛

sqlhelper调用问题

黑夜轮回 发布于 2016-11-02 08:56, 3799 次点击
我需要在aspx.cs中引用sqlhelper
需要怎么么处理啊

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using _123;

namespace _123
{
    public class SqlHelper
    {
        private String connectionString = "Server=.;database=c;uid=sa;pwd=123";

        public SqlDataReader ExecuteReader(String sql)
        {
            SqlConnection connection = new SqlConnection(connectionString);

            connection.Open();

            SqlCommand command = new SqlCommand(sql, connection);

            SqlDataReader result = command.ExecuteReader();

            return result;
        }

        public bool ExecuteCommand(String sql)
        {
            bool result = false;

            try
            {
                SqlConnection connection = new SqlConnection(connectionString);
                connection.Open();

                SqlCommand command = new SqlCommand(sql, connection);
                //command.Connection = connection;
                // = sql;
                command.ExecuteNonQuery();


                connection.Close();

                result = true;
            }
            catch (Exception e)
            {
                throw e;
            }

            return result;
        }

    }
}
2 回复
#2
lukebc2016-11-04 15:36
调用方法啊
#3
向洪林2016-11-08 13:45
自己封装sqlHelperL类吧,在sqlHelper类当中自己封装各种方法
1