OleDbConnection conn = new OleDbConnection(strDSN); OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn ); conn.Open(); DataSet ds = new DataSet(); cmd.Fill( ds, employee ); DataTable dt = ds.Tables[0]; foreach( DataRow dr in dt.Rows ) { Console.WriteLine(First name: + dr[FirstName].ToString() + Last name: + dr[LastName].ToString()); } conn.Close(); } } 十三、读取表的属性: using System; using System.Data; using System.Data.OleDb; class TestADO { static void Main(string[] args) { string strDSN = Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb; string strSQL = SELECT * FROM employee ; OleDbConnection conn = new OleDbConnection(strDSN); OleDbDataAdapter cmd = new OleDbDataAdapter( strSQL, conn ); conn.Open(); DataSet ds = new DataSet(); cmd.Fill( ds, employee ); DataTable dt = ds.Tables[0]; Console.WriteLine(Field Name DataType Unique AutoIncrement AllowNull); Console.WriteLine(==================================================================); foreach( DataColumn dc in dt.Columns ) { Console.WriteLine(dc.ColumnName+ , +dc.DataType + ,+dc.Unique + ,+dc.AutoIncrement+ ,+dc.AllowDBNull ); } conn.Close(); } } ASP.NET方面的 十四、一个ASP.NET程序: <%@ Page Language=C# %> <script runat=server> void Button1_Click(Object sender, EventArgs e) { Label1.Text=TextBox1.Text; } |