当前位置:数据库 > Access >>

C#访问ACCESS文件的简单实例

 

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Text; 

using System.Data.OleDb; 

using System.Data.SqlClient; 

 

namespace CSharpAccess 

    class Program 

    { 

        static void Main(string[] args) 

        { 

            OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/school.mdb"); 

            conn.Open(); 

            string sql = "select * from student"; 

            OleDbCommand command = new OleDbCommand(sql, conn); 

            OleDbDataReader reader = command.ExecuteReader(); 

            try 

            { 

                while (reader.Read()) 

                { 

                    for (int i = 0; i < reader.FieldCount;i++ ) 

                    { 

                        Console.Write("{0} ", reader[i]); 

                    } 

                    Console.WriteLine();                      

                } 

            } 

            finally 

            { 

                reader.Close(); 

                conn.Close(); 

            } 

        } 

    } 

}   

 

摘自 I_code

补充:软件开发 , C# ,
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,