标题:新人求大婶帮忙,代码出现问题
只看楼主
gc391462165
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-14
 问题点数:0 回复次数:1 
新人求大婶帮忙,代码出现问题
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部分显示无法访问代码,求教怎么该
搜索更多相关主题的帖子: command private public sealed 
2014-05-14 13:06
gc391462165
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-14
得分:0 
是大神!~标题打错了!~
2014-05-14 13:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-431516-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015397 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved