C#连接Access成功

| |
[不指定 2007/12/24 00:48 | by Else ]
C#链access 之前一直用链接sqlserver的函数做程序,一直出错,现在可以了
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace test.src.util
{
    public class DbConnction
    {
        public DbConnction()
        {
            //
        }

        static void Main(string[] args)
        {

            String connectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
            connectionString += @"d:\data.mdb";
            OleDbConnection myConnection = new OleDbConnection(connectionString);
            
            myConnection.Open();        //打开数据库链接
            OleDbCommand myCommand = myConnection.CreateCommand();    //定义SqlCommand变量
          

            myCommand.CommandText = "select * from ruby";           //设置SQL语句
            OleDbDataReader myDataReader = myCommand.ExecuteReader(); // 从数据库获职数据
            
            //读取DataReader中的数据并输出

            while (myDataReader.Read())
            {
                Console.WriteLine("\t{0}\t{1}", myDataReader["id"], myDataReader["title"]);
            }

            myDataReader.Close();               //关闭SqlDataReader
            myConnection.Close();               //关闭链接
            
            Console.WriteLine("这个是一个链接的测试");
        }

    }
}


作者:Else 's Blog
地址:http://www.aixq.com/post/893/
版权所有。转载时必须链接形式注明作者和原始出处及本声明!
  • 中查看更多“C#连接Access成功”相关内容
  • 中查看更多“C#连接Access成功”相关内容
  • 中查看更多“C#连接Access成功”相关内容
  • 中查看更多“C#连接Access成功”相关内容
  • 中查看更多“C#连接Access成功”相关内容
  • 中查看更多“C#连接Access成功”相关内容
  • Tags: ,
    代码 程序 编程 | 评论(0) | 引用(0) | 阅读(1472)
    发表评论
    表情
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    昵称   密码   游客无需密码
    网址   电邮   [注册]