成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WinPhone開發(fā)數(shù)據(jù)庫相關(guān)操作總結(jié)

移動開發(fā)
最古老的要數(shù)引用第三方Community.CsharpSqlite.WP.dll程序集來使用的(注意:如果你要操作現(xiàn)有存在的.sqlite數(shù)據(jù)庫,而不是自己從頭開始創(chuàng)建數(shù)據(jù)表,添加數(shù)據(jù)...等,那么你需要在codeplex網(wǎng)站上找到這個源碼,進行相應(yīng)的修改,這樣才能夠支持使用,不然會碰到很郁悶的"無法打開數(shù)據(jù)庫連接.."之類的錯誤)

1.首先來說下wp對.sqlite數(shù)據(jù)庫的操作支持,從google,百度,codeplex..等等網(wǎng)站找尋到以下方式;

(1)最古老的要數(shù)引用第三方Community.CsharpSqlite.WP.dll程序集來使用的(注意:如果你要操作現(xiàn)有存在的.sqlite數(shù)據(jù)庫,而不是自己從頭開始創(chuàng)建數(shù)據(jù)表,添加數(shù)據(jù)...等,那么你需要在codeplex網(wǎng)站上找到這個源碼,進行相應(yīng)的修改,這樣才能夠支持使用,不然會碰到很郁悶的"無法打開數(shù)據(jù)庫連接.."之類的錯誤)

(2)第二種跟***種有所類似,不過它的封裝有所不同C#-SQLiteWP7.Preview1.Release,這個也在Codeplex上面,代碼使用跟***種類似,不過里面的方法有返回DataReader之類的對象,這樣方便我們做相應(yīng)數(shù)據(jù)讀取操作,雖然數(shù)據(jù)庫也是copy到獨立存儲根目錄下的,不過這里的連接字符串有所不同,格式如下:
"Version=數(shù)據(jù)庫版本號,uri=file:你的數(shù)據(jù)庫完整名稱"

簡單的Code操作流程:

  1. using (SqliteConnection conn = new SqliteConnection("Version=3,uri=file:test.db")) 
  2.  
  3.  
  4. conn.Open(); 
  5.  
  6. using (SqliteCommand cmd = conn.CreateCommand()) 
  7.  
  8.  
  9. cmd.CommandText = "sql語句"
  10.  
  11. cmd.ExecuteNonQuery(); 
  12.  
  13.  
  14.  
  15. cmd.Transaction = conn.BeginTransaction(); 
  16.  
  17. //sql語句加入?yún)?shù) 
  18. cmd.CommandText = "INSERT INTO test(col, col2, col3, col4, col5) VALUES(@col, @col2, @col3, @col4, @col5);SELECT last_insert_rowid();"
  19.  
  20. cmd.Parameters.Add("@col"null); 
  21.  
  22. cmd.Parameters.Add("@col2"null); 
  23.  
  24. cmd.Parameters.Add("@col3"null); 
  25.  
  26. cmd.Parameters.Add("@col4"null); 
  27.  
  28. cmd.Parameters.Add("@col5"null); 
  29.  
  30. cmd.Transaction.Commit(); 
  31.  
  32. cmd.Transaction = null

如果自己不想改Community.CsharpSqlite.WP這個源碼的話,那就在網(wǎng)上找找Vici.CoolStorage.WP7和Vici.Core.WP7這兩個程序集,個人感覺這個方式,代碼操作簡單,性能較***種好些許;

  1. //注意:先往項目添加Vici.CoolStorage.WP7.dll和Vici.Core.WP7.dll          
  2. string fn = "MNSECRET.DB";//您的數(shù)據(jù)庫名稱,注意放在項目根目錄下,且設(shè)置生成操作為Resource,不復(fù)制 
  3.             Assembly assem = Assembly.GetExecutingAssembly(); 
  4.             string assemeblyName=assem.FullName.Substring(0, assem.FullName.IndexOf(',')); 
  5.             Uri dbURi= new Uri("/" + assemeblyName + ";component/" + fn, 
  6.       UriKind.Relative); 
  7.             //程序***次運行把SQLite數(shù)據(jù)庫Copy到本地存儲 
  8.             StreamResourceInfo sr = Application.GetResourceStream(dbURi); 
  9.             IsolatedStorageFile iStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
  10.             if (!iStorage.FileExists(fn)) 
  11.             { 
  12.                 using (var outputStream = iStorage.OpenFile(fn, FileMode.CreateNew)) 
  13.                 { 
  14.                     byte[] buffer = new byte[10000]; 
  15.                     for (; ; ) 
  16.                     { 
  17.                         int read = sr.Stream.Read(buffer, 0, buffer.Length); 
  18.  
  19.                         if (read <= 0
  20.                             break
  21.  
  22.                         outputStream.Write(buffer, 0, read); 
  23.                     } 
  24.                 } 
  25.             } 
  26.             //連接數(shù)據(jù)庫 
  27.             CSConfig.SetDB(fn); 
  28.             //數(shù)據(jù)操作 
  29.             CSGenericRecordList cslis = CSDatabase.RunQuery("SELECT* FROM CITY");//可以理解為返回一個表格 
  30.              foreach (CSGenericRecord cs in cslis) 
  31.              { 
  32.                  //取表中的每一行數(shù)據(jù) 
  33.                  string result= cs["數(shù)據(jù)表字段名"].ToString(); 
  34.  
  35.              } 

本文鏈接:http://wp.662p.com/thread-8290-1-1.html

責(zé)任編輯:chenqingxiang 來源: wp.662p
相關(guān)推薦

2010-05-31 15:12:44

MySQL數(shù)據(jù)庫

2011-08-30 14:25:06

QT數(shù)據(jù)庫

2011-08-05 14:02:17

MySQL數(shù)據(jù)庫異常處理

2009-08-07 18:07:58

C#數(shù)據(jù)庫開發(fā)

2011-08-30 13:40:28

MySQL線程

2019-11-07 15:39:36

數(shù)據(jù)庫MySQL文章

2009-11-13 17:31:06

ADO.NET Acc

2011-08-18 19:10:27

DB2數(shù)據(jù)庫命令

2010-01-07 17:24:12

VB.NET連接數(shù)據(jù)庫

2011-08-24 17:08:28

Oracle數(shù)據(jù)庫歸檔模式

2016-12-29 12:24:33

MySQL數(shù)據(jù)庫移植

2019-01-02 11:10:40

MySQL數(shù)據(jù)庫數(shù)據(jù)庫設(shè)計

2011-08-02 16:43:26

iPhone開發(fā) Ssqlite3 數(shù)據(jù)庫

2010-06-30 10:37:55

MS-SQL Serv

2021-07-01 06:19:46

Redis數(shù)據(jù)庫API

2010-01-28 14:42:31

Android數(shù)據(jù)庫

2011-08-01 13:59:22

Oracle數(shù)據(jù)庫命名空間

2009-01-11 09:14:45

Javascript開發(fā)總結(jié)

2009-12-29 11:15:45

ADO數(shù)據(jù)庫

2019-07-11 08:45:00

MySQL數(shù)據(jù)庫緩存
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产精品不卡 | 亚洲视频一区二区三区 | 久久一二区 | 中文字幕一区二区三区四区五区 | 人人爽人人爽人人片av | 国产精品99久久久久久宅男 | 久久不卡 | 欧美日韩在线不卡 | 国产一区二区黑人欧美xxxx | 99精品99 | 免费毛片网站 | 亚州激情 | 精品免费国产视频 | 日韩蜜桃视频 | 日日干天天操 | 男女羞羞免费视频 | 青青草久久 | 色综合一区二区三区 | 在线免费观看毛片 | 国产一区二区三区色淫影院 | 精品一级| 中文字幕爱爱视频 | 欧美激情视频一区二区三区在线播放 | 日韩视频在线观看中文字幕 | 国产网站在线免费观看 | 伊人爽 | 色婷婷久久久久swag精品 | 91精品国产综合久久久久 | 久国产视频 | 久久伊人影院 | 久操av在线| 一区二区三区影院 | 欧美理伦片在线播放 | 国产视频第一页 | 国产精品免费在线 | 国产永久免费 | 91在线免费视频 | 草久在线 | 国产精品自在线 | 久久久精品综合 | 人人人人干 |