#眉標=Mobile、.NET CF、Web Services #副標=Windows Mobile開發系列(15) #大標=行動裝置的資料存取(下) #作者=文/圖 沈炳宏 ============= 程式1 Private Sub Send (ByVal buffer() As Byte, _ ByVal bufferLen As Integer) Dim client As IrDAClient = Nothing Try client = New IrDAClient(ServiceName) Catch se As SocketException End Try Dim stream As System.IO.Stream Try stream = client.GetStream() stream.Write(buffer, 0, bufferLen) Finally If (Not stream Is Nothing) Then stream.Close() End If If (Not client Is Nothing) Then client.Close() End If End Try End Sub ================ ============= 程式2 Shared Sub Send(server As String, port as Integer, _ message As String) Dim client As TcpClient Try client = New TcpClient(server, port) Dim stream As NetworkStream = client.GetStream() … Catch e As SocketException Finally If not client is nothing Then client.Close() End Try End Sub ================ ============= 程式3 Dim al As New ArrayList() Dim dr As SqlDataReader Dim cn As New SqlConnection(_connection) Dim cm As New SqlCommand(sql, cn) cn.Open() dr = cm.ExecuteReader( CommandBehavior.CloseConnection) Do While dr.Read() al.Add(dr[0])) Loop dr.Close() ================