Beispiel #1
0
        static void Main(string[] args)
        {
            string mdbFile = @"G:\Projects\Visual Studio Project\Phillip\AccessProject\mdb\Logger.mdb";           //默認路徑  

            MDBHelp   mdbHelp = new MDBHelp(mdbFile);
            DataTable dt      = null;

            try
            {
                mdbHelp.Open();     // 打開數據庫  

                dt = mdbHelp.GetDataTable("select* from events where datatime > '2005/08/23 08:47:46.734'");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    foreach (DataColumn item in dt.Columns)
                    {
                        Console.Write(item.ColumnName + ":" + dt.Rows[i][item].ToString() + "\t");
                    }
                    Console.WriteLine();
                }

                mdbHelp.Close();    // 關閉數據庫  
            }
            finally
            {
                mdbHelp = null;
            }
            Console.ReadKey();
        }
Beispiel #2
0
        private void InputData(string gun, String db)
        {
            var    msg     = "";
            string mdbFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, db);  

            MDBHelp      mdbHelp   = new MDBHelp(mdbFile);
            SQLiteHelper sqlHelper = new SQLiteHelper();

            //sqlHelper.Execute("DROP TABLE 'SLR'");
            sqlHelper.Execute("CREATE TABLE \"" + gun + "\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \"dataNo\" TEXT ( 255 ), \"datas\" TEXT ( 255 ), \"descs\" TEXT ( 255 ) );");
            try
            {
                mdbHelp.Open();
                var d           = new Dictionary <string, string>();
                var ds1         = mdbHelp.GetDataSet("select *  from M24狙;");
                var ColumnsList = ds1.Tables[0].Columns;
                foreach (DataRow item in ds1.Tables[0].Rows)

                {
                    msg = "<ROW ";

                    d = new Dictionary <string, string>();

                    foreach (DataColumn item1 in ColumnsList)

                    {
                        var ColumnName = item1.ColumnName;

                        d.Add(ColumnName, item[ColumnName].ToString());
                    }

                    int    _id    = Convert.ToInt32(d["ID"]);
                    string dataNo = d["弹道编号"];
                    string datas  = d["弹道数据"];
                    string descs  = d["弹道备注"];
                    msg += string.Format("ID=\"{0}\" 弹道编号=\"{1}\" 弹道数据=\"{2}\"  弹道备注=\"{3}\" ", _id, dataNo, datas, descs);

                    msg += "></ROW>";

                    // 写入sqlite

                    string sql = string.Format("INSERT INTO \"" + gun + "\" (\"ID\", \"dataNo\", \"datas\", \"descs\") VALUES ({0}, '{1}', '{2}', '{3}');", _id, dataNo, datas, descs);
                    int    i   = sqlHelper.Execute(sql);
                    //LogHelper.ShowLog("row info: {0}", msg);
                    //LogHelper.ShowLog("inset status: {0}", i);
                }
            } catch (Exception e)
            {
                LogHelper.ShowLog("open MDB {0}", e.Message);
            } finally
            {
                /**
                 * mdbHelp.Close();
                 * mdbHelp = null;
                 * sqlHelper.Close();
                 * sqlHelper = null;
                 **/
            }
            LogHelper.ShowLog("{0} 数据导入完成", gun);
        }