using System.Data.OleDb; public DataView GetSata(string sqlcmd) { System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(); try { conn.ConnectionString = "FIL=MS Access;DSN=ProjectManage"; conn.Open(); System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(sqlcmd, conn); DataTable dt = new DataTable(); da.Fill(dt); return dt.DefaultView; } catch (Exception ex) { // MessageBox.Show(ex.Message); return null; } finally { conn.Close(); } }
這種連接方式比直接使用DataSet 和DataSet1TableAdapters 要好。sql
簡單方便明瞭。blog