从工具栏里面拖一个OleDbConnection进去,然后新建连接,提供程序选择Microsoft Jet4.0 OLE Provider。然后在连接中选择你的mdb文件即可。
解决方案 »
- 带几个问题来跪求各位师兄姐赐教...不胜感激!!!
- javacript radio 问题
- 请问this.CreateGraphics()和PaintEventArgs e.Graphics的区别
- 怎么把FK一起打包到SETUP啊
- 托管 EE 不理解表达式的语法??
- WebServers中如何将SqlCommand序列化?
- UDPSocket编程:当服务器位于外网时,内网用户可以与服务器通讯吗
- treeview复制
- 请教:在asp.net中调用c#编写的com+组件,总是出现 异常信息System.UnauthorizedAccessException
- 如何单击按钮时,使listView选项中的蓝色光条跟随显示
- 大家帮帮我??????
- 咋连接sql server ?
OleDbConnection cn = new OleDbConnection(strConnection);try
{
cn.Open();
MessageBox.Show("连接成功!");
}
catch( OleDbException ex )
{
MessageBox.Show( ex.Message );
}
finally
{
cn.Close();
}
visual studio.net 2003
Copy到一个Button的OnClick事件里执行一下就可得到结果
Source=c:\db1.mdb";//注意修改成你真是存在的文件如果是Web的需要给ASP.NET用户权限
如果是XP或windows2003,工具->文件夹选项->取消简单文件共享
MDB文件->右键->添加everyone完全权限
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;namespace WindowsApplication4
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Data.OleDb.OleDbConnection oleDbConnection1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// oleDbConnection1
//
this.oleDbConnection1.InfoMessage += new System.Data.OleDb.OleDbInfoMessageEventHandler(this.oleDbConnection1_InfoMessage);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} private void button1_Click(object sender, System.EventArgs e)
{
string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\db1.mdb;";
OleDbConnection cn = new OleDbConnection(strConnection); try
{
cn.Open();
MessageBox.Show("连接成功!");
}
catch( OleDbException ex )
{
MessageBox.Show( ex.Message );
}
finally
{
cn.Close();
}
} private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e)
{
}
}
}
http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=zh-cn
{
string source=@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=e:\North.mdb";
string strsql="select * from supply"; OleDbDataAdapter da=new OleDbDataAdapter(strsql,source);
DataSet ds=new DataSet();
da.Fill(ds,"tab");
dataGrid1.SetDataBinding(ds,"tab");}
缺少USING引用,命名空间是什么啊?
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data; -------->加這行
using System.Data.OleDb; -------->加這行
然后在控件里加上面的代碼
缺少USING引用