安然不哭-西坝阿超个人博客

做技术一定要一颗恒心,这样才不会半途而废。

c# sql帮助类

2018-5-6 钟建超

sqlite

public class SqliteHelp
    {
        string path = "Data Source =" + System.Windows.Forms.Application.StartupPath + "/all.db;Pooling=true;FailIfMissing=false";
        public DataTable select(SQLiteCommand comm)
        {
            using (SQLiteConnection conn=new SQLiteConnection(path))
            {
                conn.Open();
                comm.Connection = conn;
                SQLiteDataAdapter adpter = new SQLiteDataAdapter(comm);
                DataTable dt = new DataTable();
                adpter.Fill(dt);
                return dt;
            }
        }
        public int update(SQLiteCommand comm)
        {
            using (SQLiteConnection conn=new SQLiteConnection(path))
            {
                conn.Open();
                comm.Connection = conn;
                return comm.ExecuteNonQuery();
            }
        }
    }

获取路径请参考

http://blog.achao.cc/16.html


mysql

    class MysqlHelp
    {
        string path = "server=127.0.0.1;port=3306;user=root;password=root; database=minecraftdb;";
        public DataTable select(MySqlCommand comm)
        {
            DataTable dt = new DataTable();
            using (MySqlConnection conn = new MySqlConnection(path))
            {
                conn.Open();
                comm.Connection = conn;
                MySqlDataAdapter adapter = new MySqlDataAdapter(comm);
                adapter.Fill(dt);
            }
            return dt;
        }
        public int update(MySqlCommand comm)
        {
            int temp = 0;
            using (MySqlConnection conn = new MySqlConnection(path))
            {
                conn.Open();
                comm.Connection = conn;
                temp = comm.ExecuteNonQuery();
            }
            return temp;
        }
    }









标签: c#