小弟在网上查到一下关于PPC与主机同步相关代码,但是始终都调试不成功,恳请各路朋友帮帮我,帮我试试看哪里出问题,希望有调试成功的朋友可以把代码发给我,万分感谢各位关注,谢谢了 我的邮箱是www@zxdn.com.cn
以下的代码,我在“冰可乐”这位朋友的博客看到的
Host = Trim(tbHost.Text)
Internet = Trim(tbInternet.Text)
Usr = Trim(tbUsr.Text)
Pwd = Trim(tbPwd.Text)
sqlHost = Trim(tbsqlHost.Text)
sqlData = Trim(tbsqlData.Text)
sqlTable = Trim(tbsqlTable.Text)
sqlUsr = Trim(tbsqlUsr.Text)
sqlPwd = Trim(tbsqlPwd.Text)
SQL = "_update setup set host=’" + Host + "’,internet=’" + Internet + "’,usr=’" + Usr + "’,pwd=’" + Pwd + "’,sqlhost=’" + sqlHost + "’,sqldata=’" + sqlData + "’,sqltable=’" + sqlTable + "’,sqlusr=’" + sqlUsr + "’,sqlpwd=’" + sqlPwd + "’"
Call RunSqlTransaction("Data Source=" + myAppPath + "\main.sdf", SQL, "_update")
’检测PDA是否已与主机连接
Dim a As System.Net.IPHostEntry
Try
a = Dns.Resolve(Host)
Catch ex As Sockets.SocketException
If ex.ErrorCode = 11001 Then
MsgBox("没有和主机建立连接!请连接后再试。", MsgBoxStyle.Critical, "提示")
Else
MsgBox("PDA没有和主机建立连接,同步将不能继续!", MsgBoxStyle.Critical, "提示") ’ex.Message.ToString + vbCrLf + "可能是
End If
Exit Sub
End Try
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor()
Dim rdaOleDbConnectString As String = _
"Provider=sqloledb; Data Source=" + sqlHost + ";Initial Catalog=" + sqlData + "; User Id=" + sqlUsr + ";Password=" + sqlPwd
’ Initialize RDA Object.
Dim rda As SqlServerCe.SqlCeRemoteDataAccess = Nothing
’****************************************
’把PDA上新增、修改、删除的数据传回SQL SERVER
’sbSync.Text = "把PDA上新增、修改、删除的数据传回到主机..."
Try
’Try the Push Operation.
rda = New SqlServerCe.SqlCeRemoteDataAccess
rda.InternetLogin = Usr
rda.InternetPassword = Pwd
rda.InternetUrl = Internet ’"http://winxp/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=" + myAppPath + "\main.sdf"
rda.Push(sqlTable, rdaOleDbConnectString, SqlServerCe.RdaBatchOption.BatchingOn)
Catch ee As SqlServerCe.SqlCeException
’sbSync.Text = "同步出现错误,请查看错误信息,并重新进行同步。"
’ShowErrors(ee)
’MsgBox("同步时产生数据冲突(同一代码在PDA与主机上同时做过新增),同步将继续,但在PDA上所做的修改将不能同步到主机!", MsgBoxStyle.Information, "提示")
rda.Dispose()
’System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default()
’Exit Sub
End Try
’*********************************************
’删除主数据库中的MAIN数据表
’sbSync.Text = "正在删除PDA上的数据表..."
Call RunSqlTransaction("Data Source=" + myAppPath + "\main.sdf", "_drop table main", "SYNC")
rda.Dispose()
’把主机上的数据表同步回PDA
’sbSync.Text = "开始与主机的同步,数据将从主机COPY到PDA..."
Try
’Try the Pull operation.
rda = New SqlServerCe.SqlCeRemoteDataAccess
rda.InternetLogin = Usr
rda.InternetPassword = Pwd
rda.InternetUrl = Internet ’"http://winxp/sqlce/sscesa20.dll"
rda.LocalConnectionString = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=" + myAppPath + "\main.sdf"
rda.Pull("main", "select * from " + sqlTable, rdaOleDbConnectString, SqlServerCe.RdaTrackOption.TrackingOn)
Catch ex As SqlServerCe.SqlCeException
’sbSync.Text = "同步出现错误,请查看错误信息,并重新进行同步。"
ShowErrors(ex)
rda.Dispose()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default()
Exit Sub
End Try
rda.Dispose()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default()
MsgBox("已完成主机与PDA的数据同步!", MsgBoxStyle.Information, "提示")