| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 411 人关注过本帖
标题:初学者,请教大哥大姐,解决下问题~~~~~ 谢谢
只看楼主 加入收藏
liuxiaohuliu
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-7-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
初学者,请教大哥大姐,解决下问题~~~~~ 谢谢
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;


namespace demeter_dm.business
{
    /// <summary>
    /// 数据库连接方式。
    /// </summary>
    public enum DbConnectionStyle
    {
        Normal = 0,

        SYSDBA = 1,

        SYSOPER = 2
    }

    /// <summary>
    /// 数据库连接。
    /// </summary>
    public class DbConnection
    {
        public DbConnection()
        {
        }

        /// <summary>
        /// 设置连接参数。
        /// </summary>
        public void setConnectParameters(string username, string password, string database, DbConnectionStyle dbConnectionStyle, string server)
        {
            if (connection == null)
            {
                connection = new OracleConnection();
            }
            else
            {
                disposeConnection();
            }
           
            connection.ConnectionString = string.Format("Data Source={0};User Id={1};Password={2};Integrated Security=no;",
                database,username,password);        
        }

        /// <summary>
        /// 打开连接。
        /// </summary>
        public void open()
        {
            if ((connection != null)
                && (connection.State == ConnectionState.Closed))
            {
                connection.Open();
            }
        }

        /// <summary>
        /// 关闭连接。
        /// </summary>
        public void close()
        {
            if ((connection != null)
                && (connection.State != ConnectionState.Closed))
            {
                connection.Close();
            }
        }

        /// <summary>
        /// 执行 SQL 语句,获取 IDataReader。
        /// </summary>
        public IDataReader executeReader(string sql)
        {
            open();

            IDataReader dataReader;
            IDbCommand command = connection.CreateCommand();
             = sql;
            dataReader = command.ExecuteReader();
            return dataReader;
        }

        public void dispose()
        {
            disposeConnection();
        }

        private void disposeConnection()
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
            connection.Dispose();
            connection = null;
        }

        private OracleConnection connection;
    }
}
报错如下:
未处理 System.NullReferenceException
  Message="未将对象引用设置到对象的实例。"
  Source="demeter_dm"
  StackTrace:
       在 demeter_dm.business.DbConnection.setConnectParameters(String username, String password, String database, DbConnectionStyle dbConnectionStyle, String server) 位置 E:\work\internal\zhjc\bj_svn\project\demeter_analysis\business\DbConnection.cs:行号 47
       在 demeter_dm.forms.mainForm.button1_Click(Object sender, EventArgs e) 位置 E:\work\internal\zhjc\bj_svn\project\demeter_analysis\forms\mainForm.cs:行号 56
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(Form mainForm)
       在 demeter_dm.Program.Main() 位置 E:\work\internal\zhjc\bj_svn\project\demeter_analysis\business\Program.cs:行号 19
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:
搜索更多相关主题的帖子: 大姐 
2010-07-01 10:04
fanxuechao
Rank: 2
来 自:新疆
等 级:论坛游民
帖 子:19
专家分:27
注 册:2010-6-9
收藏
得分:20 
我也是处学着!!!!...........看看!!!!
2010-07-01 10:17
快速回复:初学者,请教大哥大姐,解决下问题~~~~~ 谢谢
数据加载中...
 
   



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

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