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 源码下载地址

感悟:别因为自己很菜,而去抹杀自己的想法。世界上很多工具,系统,架构都是人写出来的,不是神写出来的。

转载于:https://www.cnblogs.com/tangdacheng/archive/2012/12/08/2808438.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值