源于对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 只是简单的实现。
https://files.cnblogs.com/tangdacheng/MySQL.zip 源码下载地址
感悟:别因为自己很菜,而去抹杀自己的想法。世界上很多工具,系统,架构都是人写出来的,不是神写出来的。