当前位置:数据库 > 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# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,