using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//构造连接字符串
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection +=@"Data Source=\\192.168.1.10\\access\\CSharptest.mdb";
OleDbConnection objConnection = new OleDbConnection(strConnection); //建立连接
objConnection.Open(); //打开连接
OleDbCommand sqlcmd = new OleDbCommand(@"select * from person where personname='John'",objConnection); //sql语句
OleDbDataReader reader = sqlcmd.ExecuteReader(); //执行查询
int age = new int();
if(reader.Read()){ //这个read调用很重要!不写的话运行时将提示找不到数据
age = (int)reader["age"]; //取得字段的值
objConnection.Close();
reader.Close();
}
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载