Windows Mobile6.5開發(二)–配置環境,資料庫訪問,部署簡單一實例

來源:互聯網
上載者:User

一 首先配置開發環境:

系統內容:Microsoft Windows XP Professional 版本2002 Service Pack 3

需要安裝軟體:

1 Visual Studio 2008 RTM  &&  .NET Framework Version 3.5 SP1 英文版

2 ActiveSync 4.5 setup chs

3 Windows Mobile 6 Professional SDK Refresh.msi

4 Windows Mobile 6 Standard SDK Refresh.msi 非必需

5 Windows Mobile 6.5 Professional Developer Tool Kit (USA).msi

6 Windows Mobile 6.5 Standard Developer Tool Kit (USA).msi 非必需

7 Windows Mobile 6.5.3 Professional DTK.msi

8 MobileFormsToolkitEnterprise.2010.msi(Resco Control)

9 AL6804.zip(patch for Resco Control)

安裝完成之後,配置開發模擬器環境:

1 ActiveSync 設定:檔案-串連設定:允許串連到以下其中一個連接埠 選擇DMA

2 vs2008菜單 Tools-Device Emulator Manager- 選擇Windows Mobile 6.3.5 Professional WVGAEmulator右鍵Connect

等待重新整理,然後右鍵Cradle建立同步

然後出現同步設定嚮導,下一步,然後根據需求完成嚮導。

3 配置模擬器環境:安裝幾個cab包:

NETCFv35.Messages.EN.wm.cab

NETCFv35.wm.armv4i.cab

sqlce.phone.wce5.armv4i.CAB 優先於以下2個安裝

sqlce.dev.ENU.phone.wce5.armv4i.CAB

sqlce.repl.phone.wce5.armv4i.CAB

SyncServices.wm.cab

二建立樣本程式:

File-New-New Project:Smart Device Project : MyFirstWMProject

選擇Windows Mobile 6 Professional SDK 和.NET  Framework Compact Version 3.5

項目類型:Device Application

1 首先建立一個SQL CE 資料庫:

Tools –Connect To DataBase – Add Connecttion

Data source 選擇Microsoft SQL Server Compact3.5

點擊Create ,點擊Browse選擇項目路徑,確定後修改資料庫名稱:TestDB

結果類似:D:\workspace\MyFirstWMProject\MyFirstWMProject\TestDB.sdf

輸入訪問密碼:123456

在Server Explorer 視窗內,操作建立立的資料庫,建立表,列等

TestTb:包含一個自增的id列和一個Name列

右鍵點擊表Show Table data 然後添加幾條資料

2 拖放一個button和一個dataGrid放在頁面上,在button的click時間中書寫代碼

Add References 添加System.Data.SqlServerCe引用,並且

using System.Data.SqlServerCe;

button Click事件代碼:

            string sPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());

            SqlCeConnection conn = new SqlCeConnection("Data Source=" + sPath + "\\TestDB.sdf;Password ='123456'");

            SqlCeDataAdapter da = new SqlCeDataAdapter("select * from testTb", conn);

            DataTable dt = new DataTable();

            conn.Open();

            da.Fill(dt);

            conn.Close();

            dataGrid1.DataSource = dt;

至此代碼編寫完成。

三 部署項目:2種方法

第一種方法:直接複製檔案

直接將項目產生的MyFirstWMProject.exe和資料庫檔案TestDB.sdf複製到模擬器下的同一檔案夾下

類似:複製到\My Documents\Business下面

然後進入到模擬器中,選擇菜單中的File Explorer ,進入到Business檔案夾,就可以看到這2個檔案

選擇MyFirstWMProject 點擊斷行符號,啟動程式,點擊按鈕,擷取顯示資料

第二種辦法:製作cab安裝包

Add New Project :Other Project types:Smart Device CAB Project

項目名稱:MySmartDeviceCab

在Application Folder 上右鍵Add – Add Project OutPut

選擇Primary output

然後再次右鍵Add – Add File,選擇資料庫TestDB.sdf檔案

在File System on Target Machine 上右鍵Add – Add Special Folder 選擇Start Menu Folder

然後選中該檔案夾,在右邊檔案顯示表單,右鍵Create New ShortCut,選擇pplication Folder檔案夾下的主輸出檔案,點擊確定,然後右鍵點擊剛建立的檔案,修改名稱為:MyFirstWMProject,這個就是將來在開始頁面捷徑的名稱

刪除沒用的Program Files Folder檔案夾

Build 項目,產生cab檔案包

將產生的cab包檔案複製到模擬器中,並且點擊安裝,完成之後在,就有了捷徑MyFirstWMProject

點擊捷徑就可以訪問程式了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.