编写一个程序,用来打开access程序,怎么做? 编写一个程序,用来打开access程序,怎么做?不是连接数据库哦!请各位高手赐教,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ado.net 数据库操作 dbhelper连接字符串成<add name="accessConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|a.mdb" providerName="System.Data.OleDb"/> public static OleDbDataReader ExecuteReader(string strSQL) { OleDbConnection connection = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(strSQL, connection); try { connection.Open(); OleDbDataReader myReader = cmd.ExecuteReader(); return myReader; } catch (System.Data.OleDb.OleDbException e) { throw new Exception(e.Message); } } using System; using System.Data.OleDb; class OleDbTest{ public static void Main() { //创建数据库连接 OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\db1.mdb"); //创建command对象并保存sql查询语句 OleDbCommand aCommand = new OleDbCommand("select * from emp_test", aConnection); try { aConnection.Open(); //创建datareader 对象来连接到表单 OleDbDataReader aReader = aCommand.ExecuteReader(); Console.WriteLine("This is the returned data from emp_test table"); //循环遍历数据库 while(aReader.Read()) { Console.WriteLine(aReader.GetInt32(0).ToString()); } //关闭reader对象 aReader.Close(); //关闭连接,这很重要 aConnection.Close(); } //一些通常的异常处理 catch(OleDbException e) { Console.WriteLine("Error: {0}", e.Errors[0].Message); } } } 成功运行这个程序的步骤 1.用msaccess创建一个名叫db1.mdb的数据库 2.创建一个名叫emp_test的表单 3.使它包含下列数据域 emp_code int emp_name text emp_ext text 4.将上面的代码保存到sample.cs文件中 5.确保数据库位于c:\并确保mdac2.6或是更新的版本已经被安装 6.编译运行 用API函数shellexecute(),大致这样ShellExecute(窗体句柄,null, 文件名(access是MSACCESS.EXE), null, null, 1 DLL调用值C++ 对应的C#的问题 C#读取一个二进制文件(如可运行的exe)到文本框中,结果都是0和1的字符串吗? Oracle的3113和3114错误 update不成功 为什么显示的是1而不是walker 高分求教:如何在RichTextBox中显示下面的RTF内容 为什么创建项目的时候显示“Automation服务器不能创建对象”? c#历史上最强的程序,输入一个你的图片看看 写个取硬盘号的注册程序,测试了IDE可以,但串口硬盘不行,能否给点思路,谢谢了 搞不懂了,大家来看看! LINQ 如果所查找的值有NULL报错 泛型遇上反射,求解
连接字符串成
<add name="accessConnStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source= |DataDirectory|a.mdb" providerName="System.Data.OleDb"/>
public static OleDbDataReader ExecuteReader(string strSQL)
{
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(strSQL, connection);
try
{
connection.Open();
OleDbDataReader myReader = cmd.ExecuteReader();
return myReader;
}
catch (System.Data.OleDb.OleDbException e)
{
throw new Exception(e.Message);
}
}
using System.Data.OleDb;
class OleDbTest{
public static void Main()
{
//创建数据库连接
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\db1.mdb");
//创建command对象并保存sql查询语句
OleDbCommand aCommand = new OleDbCommand("select * from emp_test", aConnection);
try
{
aConnection.Open();
//创建datareader 对象来连接到表单
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("This is the returned data from emp_test table");
//循环遍历数据库
while(aReader.Read())
{
Console.WriteLine(aReader.GetInt32(0).ToString());
}
//关闭reader对象
aReader.Close();
//关闭连接,这很重要
aConnection.Close();
}
//一些通常的异常处理
catch(OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
}
成功运行这个程序的步骤
1.用msaccess创建一个名叫db1.mdb的数据库
2.创建一个名叫emp_test的表单
3.使它包含下列数据域
emp_code int
emp_name text
emp_ext text
4.将上面的代码保存到sample.cs文件中
5.确保数据库位于c:\并确保mdac2.6或是更新的版本已经被安装
6.编译运行
大致这样ShellExecute(窗体句柄,null, 文件名(access是MSACCESS.EXE), null, null, 1