C#中检测access mdb 版本

const int VERSION_STRING_SIZE = 24;
        const int JET_2_VERSION_NUMBER_START = 1;
        const int JET_VERSION_NUMBER_START = 21;
        const int LENGTH = 1;



FileStream fs = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryReader br = new BinaryReader(fs);

            string str = new string(br.ReadChars(VERSION_STRING_SIZE));
            MessageBox.Show(str);

            if (str.Substring(JET_2_VERSION_NUMBER_START-1, LENGTH) == string.Format("{0}", (char)1))
                MessageBox.Show("Microsoft Access 2");
            else if (str.Substring(JET_VERSION_NUMBER_START-1, LENGTH) == string.Format("{0}", (char)0))
                MessageBox.Show("Microsoft Access 97");
            else if (str.Substring(JET_VERSION_NUMBER_START-1, LENGTH) == string.Format("{0}", (char)1))
                MessageBox.Show("Microsoft Access 2000/2002");
            else
                MessageBox.Show("no");        // maybe it's 2007
            br.Close();
            fs.Close();

posted @ 2008-04-15 23:08  margiex  阅读(590)  评论(0)    收藏  举报