主题:找不到类型或命名空间名称“OledDbConnection
thinkwe
[专家分:0] 发布于 2006-08-09 19:35:00
public OledDbConnection Connection
{
get
{
return _connection;
}
set
{
Disconnect();
_connection = value;
}
}
编译的时候出现错误:
错误 1 找不到类型或命名空间名称“OledDbConnection”(是否缺少 using 指令或程序集引用?) D:\c#程序学习\CustomerEditor\CustomerEditor\CustomerEditor\Form1.cs 50 16 CustomerEditor
请问如何解决!!
回复列表 (共2个回复)
沙发
thinkwe [专家分:0] 发布于 2006-08-09 19:47:00
这是整个程序,请高手指教
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;//添加OleDb命名空间
namespace CustomerEditor
{
public partial class Form1 : Form
{
//Fields....
public OleDbConnection _connection;
public Form1()
{
InitializeComponent();
}
private void menuDataConnect_Click(object sender, EventArgs e)
{
Connect();
}
public void Connect()
{
if (dialogOpenFile.ShowDialog(this) == DialogResult.OK)
{
try
{
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};User ID=;Password=;", dialogOpenFile.FileName);
OleDbConnection newConnection = new OleDbConnection(connectionString);
newConnection.Open();
connection = newConnection;
}
catch (Exception ex)
{
HandleException("A connection not a mdb", ex);
}
}
}
public void HandleException(string message, Exception ex)
{
MessageBox.Show(this, StringFormat("{0}\n{1}:{2}", message, ex.GetType().ToString, ex.Message));
}
public OledDbConnection Connection
{
get
{
return _connection;
}
set
{
Disconnect();
_connection = value;
}
}
public void Disconnect()
{
if (_connection != null)
{
if (_connection.State != ConnectionState.Closed)
{
_connection.Close();
_connection = null;
}
}
}
}
}
板凳
jzyray [专家分:20610] 发布于 2006-08-09 22:47:00
using System.Data.OleDb;
看msdn
我来回复