初学者,请教大哥大姐,解决下问题~~~~~ 谢谢
代码: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: