浅谈 SQLite

关于SQLite的介绍:http://www.codesky.net/article/201002/167887.html


下面是SQLite 调用示例:

 private void InitSQLite()
        {
            string path = "e:\\tmp";
            string dataSource = System.IO.Path.Combine(path, "test.db");

            if (!File.Exists(dataSource))
            {
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                FileStream fs = File.Create(dataSource);
                fs.Close();
            }

            SQLiteConnection.CreateFile(dataSource);
            SQLiteConnection conn = new SQLiteConnection();

            //连接数据库
            SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
            connstr.DataSource = dataSource;
            connstr.Password = "123456";

            conn.ConnectionString = connstr.ToString();
            conn.Open();

            SQLiteCommand sqlCmd = new SQLiteCommand();

            // 创建表
            sqlCmd.CommandText = "CREATE TABLE test(name VARCHAR(20),pwd VARCHAR(20))";
            sqlCmd.Connection = conn;
            sqlCmd.ExecuteNonQuery();

            //插入数据
            sqlCmd.CommandText = "INSERT INTO test VALUES('a','b')";
            sqlCmd.ExecuteNonQuery();


            //取出数据
            sqlCmd.CommandText = "SELECT * FROM test";
            SQLiteDataReader reader = sqlCmd.ExecuteReader();

            StringBuilder sb = new StringBuilder();
            while (reader.Read())
            {
                sb.Append("name:").Append(reader.GetString(0)).Append("\n");
                sb.Append("password:").Append(reader.GetString(1)).Append("\n");
            }

            MessageBox.Show(sb.ToString());
        }


你可能感兴趣的:(数据库,SQLite,数据库)