Download presentation
Presentation is loading. Please wait.
1
.NET + SQL SERVER SQL Server +SP4
7
確定加入六個參考
8
DataGrid Button2
9
DataGrid SQL ServerConnectionDataAdapterDataSetCommandDataGrid
10
code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cn As System.Data.SqlClient.SqlConnection ' 宣告 connection 物件 Dim cmd As System.Data.SqlClient.SqlCommand ' 宣告 command 物件 Dim da As System.Data.SqlClient.SqlDataAdapter ' 宣告 dataadapter 物件 ' 建立與 SQL Server 資料庫的連線 ' 產生 connection 物件 cn = New System.Data.SqlClient.SqlConnection("uid=rcjao;pwd=rcjao;database=rcjao;server=MYCHAT- 57ED6516") ' 產生 command 物件 cmd = New System.Data.SqlClient.SqlCommand("select * from myname", cn) ' 產生 dataadapter 物件 da = New System.Data.SqlClient.SqlDataAdapter(cmd) ' 加入新的資料表 ' 宣告並產生 datatable 物件 Dim dt As System.Data.DataTable = New System.Data.DataTable("myname") da.Fill(dt) DataGrid1.DataSource = dt End Sub Imports System.data Imports System.Data.SqlClient
11
部署與執行
13
部署與執行 -使用模擬器
16
部署與執行 -使用 PDA 請注意 PDA 畫面上的訊息 程式並未真正安裝到 PDA 上面
17
部署至 PDA
18
建置封包檔 畫面會閃動建置封包檔
19
建置封包檔-適合各種 PDA
20
安裝封包檔 點選執行 依照機型複製.CAB 檔案到 PDA 上
21
執行封包檔
22
表單顯示與切換
23
建立新表單
24
表單方法 Close - 關閉表單 Hide - 隱藏表單 Show - 顯示表單 ‘ Form1 呼叫顯示 Form2 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim myfrm2 As New Form2 myfrm2.Show() End Sub
25
.NET + SQL CE 由 SQL Server 下載資料
28
Module Module1 Public strremoteconnect As String ' SQL Server 連接設定 Public localconnect As String ' sdf 檔案位置設定 End Module
29
由 SQL Server 下載資料 Imports System.Data.SqlServerCe Imports System.Data Imports System.Data.SqlClient 加入 SQLCE 參考 Form2
30
由 SQL Server 下載資料 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ' 跳頁到 FORM2 Dim myfrm2 As New Form2 myfrm2.Show() End Sub Form1 Button3
31
由 SQL Server 下載資料 設定 SQL Server 連接參數 (strremoteconnect) 設定 PDA 上 SDF 檔案位置 (localconnect) Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load strremoteconnect = "provider=sqloledb;data source=192.168.2.2;Initial Catalog=wealth1;UID=mywealth;password=mywealth" localconnect = "Data Source=\My Documents\wealth1.sdf “ End Sub Form2
32
由 SQL Server 下載資料 Form2 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘ 需要 Imports System.IO ,檢查 sdf 資料庫是否存在 If System.IO.File.Exists("\My Documents\wealth1.sdf") Then System.IO.File.Delete("\My Documents\wealth1.sdf") End If ' 改變游標形狀 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor ‘ -------------------------- 建立資料庫 Dim eng As SqlCeEngine = New SqlCeEngine(localconnect) eng.CreateDatabase() ' 恢復油標形狀 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default MsgBox(" 資料庫建立成功 ") End Sub
33
由 SQL Server 下載資料 Form2 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click ' 下載資料 Dim strSQL As String = "SELECT * FROM goods" Dim rda As SqlCeRemoteDataAccess = Nothing Try rda = New SqlCeRemoteDataAccess rda.InternetUrl = “ http://192.168.2.2/rda/sscesa20.dll ” ‘ ㄧ定要指定固定且確定的 ip http://192.168.2.2/rda/sscesa20.dll rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\My Documents\wealth1.sdf" rda.Pull("goods", strSQL, strremoteconnect, RdaTrackOption.TrackingOnWithIndexes, "ErrorTable") MsgBox(" 資料下載成功 ") Catch ex As SqlCeException MsgBox(ex.Message.ToString) Finally rda.Dispose() End Try End Sub
34
由 SQL Server 下載資料 Form2 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim dt As System.Data.DataTable = New System.Data.DataTable("goods") Dim cn As New System.Data.SqlServerCe.SqlCeConnection Dim cmd As New System.Data.SqlServerCe.SqlCeCommand Dim da As New System.Data.SqlServerCe.SqlCeDataAdapter ‘ 開啟 sdf 連線 Try cn = New System.Data.SqlServerCe.SqlCeConnection("Data Source=\My Documents\wealth1.sdf") ‘ 使用 command 執行 sql 指令 cmd.CommandText = "SELECT * FROM goods" cmd.Connection = cn da = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd) da.Fill(dt) ‘ 在 DataGrid 顯示資料 DataGrid1.Visible = False DataGrid1.DataSource = dt DataGrid1.Visible = True cn.Close() cn = Nothing Catch sqlex As SqlServerCe.SqlCeException MsgBox(sqlex.Message.ToString) Catch ex As Exception MsgBox(ex.Message.ToString) End Try End Sub
35
由 SQL Server 下載資料 Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close() End Sub
36
由 SQL Server 下載資料 Form2 Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim localConnection As SqlCeConnection localConnection = New SqlCeConnection(localconnect) Dim insertData As String Dim cmdCreateTable As SqlCeCommand insertData = "update goods set stuid='11111' where name='abc'" localConnection.Open() cmdCreateTable = New SqlCeCommand(insertData, localConnection) cmdCreateTable.CommandType = CommandType.Text cmdCreateTable.ExecuteNonQuery() localConnection.Close() localConnection = Nothing MsgBox(" 修改成功 ") Call Button3_Click(0, e) ‘ 重新顯示 End Sub Convert.ToString(DataGrid1(DataGrid1.CurrentRowIndex, 0))
37
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim localConnection As SqlCeConnection localConnection = New SqlCeConnection(localconnect) Dim insertData As String Dim cmdCreateTable As SqlCeCommand ' 需要設定 SQL Server 上的 uniqueidentifier 的 RowGuid=true 才可以新增 insertData = "INSERT INTO goods (name,stuid) VALUES ('222ab','333ab')" localConnection.Open() cmdCreateTable = New SqlCeCommand(insertData, localConnection) cmdCreateTable.CommandType = CommandType.Text cmdCreateTable.ExecuteNonQuery() localConnection.Close() localConnection = Nothing MsgBox(" 新增資料成功 ") End Sub 由 SQL Server 下載資料 Form2 記得 sql server 的欄位一定要設定成 uniqueidentifier
38
由 SQL Server 下載資料 Form2 Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim rda As SqlCeRemoteDataAccess = Nothing Try rda = New SqlCeRemoteDataAccess rda.InternetUrl = “ http://192.168.2.2/rda/sscesa20.dll ” ‘ ㄧ定要指定固定且確定的 ip http://192.168.2.2/rda/sscesa20.dll rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\My Documents\wealth1.sdf" rda.Push("goods", strremoteconnect, RdaBatchOption.BatchingOn) MsgBox(" 資料上傳成功 ") Catch ex As SqlCeException MsgBox(ex.Message.ToString) Finally rda.Dispose() End Try End Sub
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.