law

law

  • NA
  • 2
  • 0

Use Access Table to Set the DataGrid Constrains

Mar 3 2009 12:06 PM
Hi All,

My Aim was to use Access Table structure to limit the Datagrid Structure, However, my code did'nt work in opening the database (Error marked as below):

        private System.Windows.Forms.DataGrid dataGridNewOrder;
        System.Data.OleDb.OleDbConnection con;
        OleDbDataAdapter adapter;
        DataSet ds;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        private void FrmNewOrder_Load(object sender, System.EventArgs e)
        {
            //SqlParameter workParam = null;
            string query = "Select ProductID, ProductName, Quantity, UnitPrice, Discount, SubtotalPrice, Remarks From OrderDetail";
            ConnectToData(query); // establish database connection and create DataSet
            dataGridNewOrder.SetDataBinding(ds, "OrderDetail");
            DataTable t = ds.Tables["OrderDetail"];
        }
        public void ConnectToData(string q)
        {
            ds = new DataSet();
            con = new System.Data.OleDb.OleDbConnection(@"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Larry\Documents\Visual Studio Projects\SOMS\bin\Debug\SOMS.mdb");
            con.Open();             <<<<<<<<<<<<<<<<<<<<<<<- ERROR
            Console.WriteLine("open Con");
            adapter = new OleDbDataAdapter(q,con);
            adapter.Fill(ds, "OrderDetail");


        }