C#小型數據庫只能查詢


源於對SQL Server  和 Oralce 的猜想,聽說都是xml為文本,猜想xml標簽對,很浪費容量,也會影響性能。

所有我寫了一個C#小型數據庫(只有查詢功能)。實現功能很少,只是想實現我的思路。就是一個簡單讀取文本,查詢功能。

ContaintFile是判斷是否含有文本

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MySQL
{
    public static class ContaintFile
    {
        #region Contain
        /// <summary>
        /// 是否含有表名的text文本
        /// </summary>
        /// <param name="name">傳入的表名</param>
        /// <returns></returns>
        public static  bool Contain(string name)
        {
            try
            {
                //得到當前程序集的路徑
                string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                //string apppath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                
               // string fileName = path.Replace("//","/" );
                DirectoryInfo dir = new DirectoryInfo(path);
                FileInfo[] textFiles = dir.GetFiles("*.txt",SearchOption.AllDirectories);
                foreach (FileInfo f in textFiles)
                {
                    return f.Name.ToString().Trim() == name.ToString().Trim();
                }

                return false;
            }
            catch
            {
                return false;
            }
        }
        #endregion
    }
}

ReadText 是讀取文本綁定DataGridView

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MySQL
{
    #region ReadText
    /// <summary>
    /// 讀取文本的靜態類
    /// </summary>
    public static class ReadText
    {
        /// <summary>
        /// 讀取所有文本的內容
        /// </summary>
        /// <param name="FileName">傳入的文件名</param>
        /// <returns></returns>
        public static List<People> ReadAll(string FileName)
        {



            string line = "";
            string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            string full = path + FileName.Trim();
            full = full.Replace("\\", System.IO.Path.DirectorySeparatorChar.ToString());
            try
            {
                //判斷是否含有文件
                if (!File.Exists(full))
                {
                    return null;
                }
                StreamReader sr = File.OpenText(full);
                if (sr == null)
                    return null;
                line = sr.ReadLine();
                List<People> ps = new List<People>();
               
                while (line != null)
                {
                    int i = 0;
                    string[] lines = line.Split(new char[] { ';' });
                    
                    People p = new People();
                    p.name = lines[i].Substring(lines[i].IndexOf("=")+1 );         
                    p.Age = lines[i+1].Substring(lines[i+1].IndexOf("=") + 1);
                    line = sr.ReadLine();
                    ps.Add(p);


                }
                return ps;
            }
            catch
            {
                return null;
            }

        }


    }
    #endregion
}

Main窗口是邏輯實現

 只能查詢 select * from 1 只是簡單的實現。

 http://files.cnblogs.com/tangdacheng/MySQL.zip 源碼下載地址

感悟:別因為自己很菜,而去抹殺自己的想法。世界上很多工具,系統,架構都是人寫出來的,不是神寫出來的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM