public static class Database { public static string PostCodeConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=X:\\DATA\\PostCode.mdb;Persist Security Info=True;Jet OLEDB:Database Password=4410210091"; public static string CONTACTConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=X:\\DATA\\CONTACT.mdb;Persist Security Info=True;Jet OLEDB:Database Password=4410210091"; public static System.Data.DataTable GetTableForm(string _SQL, string strConn) { System.Data.DataSet ds = new System.Data.DataSet(); System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn); conn.Open(); System.Data.OleDb.OleDbDataAdapter adapter2 = new System.Data.OleDb.OleDbDataAdapter(_SQL, conn); adapter2.Fill(ds); return ds.Tables[0]; } }
public static class Database { public static string PostCodeConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=X:\\DATA\\PostCode.mdb;Persist Security Info=True;Jet OLEDB:Database Password=4410210091"; public static string CONTACTConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=X:\\DATA\\CONTACT.mdb;Persist Security Info=True;Jet OLEDB:Database Password=4410210091"; public static string SQL_1 = "SELECT pvnID, Province, Symbol FROM Sett_Post_Province"; public static System.Data.DataTable GetTableForm(string _SQL, string strConn) { System.Data.DataSet ds = new System.Data.DataSet(); System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn); conn.Open(); System.Data.OleDb.OleDbDataAdapter adapter2 = new System.Data.OleDb.OleDbDataAdapter(_SQL, conn); adapter2.Fill(ds); return ds.Tables[0]; } }
private void Form2_Load(object sender, EventArgs e) { dataGridView1.DataSource = Database.GetTableForm(Database.SQL_1, Database.PostCodeConnectionString).DefaultView; }