注册 登录
编程论坛 C# 论坛

新人求大婶帮忙,代码出现问题

gc391462165 发布于 2014-05-14 13:06, 502 次点击
namespace WebApplication1.cs
{
   
        /// <summary>
        ///
        /// </summary>
        sealed internal class StoredProcedure : IDisposable {
            public string ErrorMessage = "";
            private System.Data.SqlClient.SqlCommand command;
            public StoredProcedure(string sqlText){
                ConfigManager config =new ConfigManager();
                command = new SqlCommand(sqlText, new SqlConnection(config.DALConnectionString));
               
                command.Connection.Open();}
            /// <summary>
            ///
            /// </summary>
            public void Dispose(){
                if(command!=null)
                {
                SqlConnection connection=command.Connection;
                Debug.Assert(connection!=null);
                command.Dispose();
                command=null;
                connection.Dispose();
                }
            }
            /// <summary>
            /// <returns></returns>
            /// </summary>
            public int Run()
            {
                if (command != null)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                    try
                    {
                        command.ExecuteNonQuery();
                        return 1;
                    }
                    catch (Exception e)
                    {
                        ErrorMessage = e.Message;
                        return 0;
                    }
                }
            }
            /// <summary>
            ///
            /// </summary>
            /// <param name="dataTable"></param>
            /// <returns></returns>

            public int Run(DataTable dataTable){
                if(command==null)
                    throw new ObjectDisposedException(GetType().FullName);
                try{
                    SqlDataAdapter dataAdapter =new SqlDataAdapter();
                    dataAdapter.SelectCommand= command;
                    dataAdapter.Fill(dataTable);
                    return 1;
                }
                catch(Exception e){
                    ErrorMessage=e.Message;
                    return 0;
                }
            }

        }

run()部分显示不是所以数据有返回值,try部分显示无法访问代码,求教怎么该
1 回复
#2
gc3914621652014-05-14 13:07
是大神!~标题打错了!~
1