Download presentation
Presentation is loading. Please wait.
1
.NET + SQL SERVER SQL Server +SP4
8
DataGrid Button2
9
DataGrid SQL Server Connection Command DataAdapter DataSet DataGrid
10
code Dim cn As System.Data.SqlClient.SqlConnection
Dim cmd As System.Data.SqlClient.SqlCommand Dim da As System.Data.SqlClient.SqlDataAdapter ' 建立與SQL Server資料庫的連線 cn = New System.Data.SqlClient.SqlConnection("uid=nwd;pwd=nwd;database=Northwind;server= ") cmd = New System.Data.SqlClient.SqlCommand("select * from employees", cn) da = New System.Data.SqlClient.SqlDataAdapter(cmd) ‘ 加入新的資料表 Dim dt As System.Data.DataTable = New System.Data.DataTable("employees") da.Fill(dt) DataGrid1.DataSource = dt
11
部署與執行
12
部署與執行
13
部署與執行 -使用模擬器
14
部署與執行 -使用模擬器
15
部署與執行 -使用模擬器
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下載資料
26
由SQL Server下載資料
27
由SQL Server下載資料
28
由SQL Server下載資料 Module Module1
Public strremoteconnect As String ' SQL Server連接設定 Public localconnect As String ' sdf檔案位置設定 End Module
29
由SQL Server下載資料 Form1 Imports System.Data.SqlServerCe
Imports System.Data.SqlClient 加入SQLCE參考
30
由SQL Server下載資料 Form1 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 Button3
31
由SQL Server下載資料 Form2 設定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= ;Initial Catalog=wealth1;UID=mywealth;password=mywealth" localconnect = "Data Source=\My Documents\wealth1.sdf“ End Sub
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 = " 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 cmd As New System.Data.SqlServerCe.SqlCeCommand ‘ 開啟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 End Sub
37
由SQL Server下載資料 Form2 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
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 = " 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.