//1.给不带密码的数据库添加密码
string strconn = @"Data Source=E:\test.db3;Pooling=true;FailIfMissing=false";
SQLiteConnection conn = new SQLiteConnection(strconn);
conn.Open();
//首次设置密码
conn.ChangePassword("password");
conn.Close();

//2.读取带密码的数据
string strconn = @"Data Source=E:\test.db3;Pooling=true;FailIfMissing=false";
SQLiteConnection conn = new SQLiteConnection(strconn);
//输入密码
conn.SetPassword("password");
string sql = "select * from tb";
SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql, conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];

//3.修改数据库密码
string strconn = @"Data Source=E:\test.db3;Pooling=true;FailIfMissing=false";
SQLiteConnection conn = new SQLiteConnection(strconn);
//数据原来密码
conn.SetPassword("old_password");
conn.Open();
//设置新密码
conn.ChangePassword("new_password");
conn.Close();

posted on 2011-09-05 15:51  josephus  阅读(1249)  评论(0编辑  收藏  举报