您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 嵌入式开发 > 正文
·速成电脑精英(包分配)白领高薪一族从这里开始



-Java套接字编程(下)
-MediaStudio Pro 6.5教程
-三款卸载软件最新试用
-基于Visual C++的Winsock API研究

Pocket PC应用程序中使用SQL Server CE
2002-11-11· ·crystal编译··yesky

上一页  1 2 3 4  下一页

  调用Web Sevice

  对于特殊的书籍查询,应用程序将调用Web Sevice,在.NET CF中调用Web Sevice与在.NET Framework中没有什么差别,要注意的是Web Sevice必须与实际机器上使用的名称相同,否则Web Sevice将不会工作。

  下面将Web Sevice与ComboBox控件绑定:

Private Sub cmdSearch_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdSearch.Click
Dim ws As New TitlesWS.Service1()
' get the web service
ds = ws.getTitles(txtSearch.Text)
cboResult.DataSource = ds.Tables(0)
cboResult.DisplayMember = "title"
End Sub

  实际上当书名被选定后,他更多的信息将显示在label控件上。

Private Sub cboResult_SelectedIndexChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cboResult.SelectedIndexChanged
' display the information of the
' selected book.
Dim row As DataRow
row = ds.Tables("titles").Rows( _
cboResult.SelectedIndex)
lblTitleID.Text = row.Item("title_id")
lblPrice.Text = "$" & row.Item("price")
txtNotes.Text = row.Item("notes")
End Sub


      图6

  显然ADD按钮用于增加订单中的数量,因此必须给ADD按钮添加一个单击事件:

Private Sub cmdAdd_Click( ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles cmdAdd.Click
'---add the title to the stores ORDER table
conn.Open()
Dim sql As String = "INSERT INTO Orders " &_
"(storeID, title_id, Qty) VALUES (" & _
cboStoreID.Items(cboStoreID.SelectedIndex) _
& ",'" & _
lblTitleID.Text & "'," & txtQty.Text & ")"
Dim cmd As New SqlCeCommand(sql, conn)
cmd.ExecuteNonQuery()
MsgBox("Title added for " & lblStoreName.Text, _
MsgBoxStyle.Information, "Orders")
conn.Close()
End Sub

  返回消息框证实增加数量。


      图7

  审核订单

  点击第二个tab页显示订单,点击Refresh按钮第一个ListBox控件将显示订单。

Private Sub cmdRefresh_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdRefresh.Click
'---displays the list of stores available
conn.Open()
Dim sql As String = "SELECT * FROM Stores"
Dim cmd As New SqlCeCommand(sql, conn)
Dim reader As SqlCeDataReader = _
cmd.ExecuteReader
'---clears the listbox
cboStoreIDs.Items.Clear()
While reader.Read()
cboStoreIDs.Items.Add( _
reader.Item("storeID"))
End While
conn.Close()
End Sub

  当一个书店被选中之后,该书店相应的订单就会显示在第二个Listbox控件中。

Private Sub cboStoreIDs_SelectedIndexChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cboStoreIDs.SelectedIndexChanged
'---displays the orders of store selected
conn.Open()
Dim sql As String = _
"SELECT * FROM Orders WHERE storeID=" & _
cboStoreIDs.Items(cboStoreIDs.SelectedIndex)
Dim cmd As New SqlCeCommand(sql, conn)
Dim reader As SqlCeDataReader = _
cmd.ExecuteReader()
'---clears the listbox
cboOrders.Items.Clear()
While reader.Read()
cboOrders.Items.Add( _
reader.Item("title_id") & " - " & _
reader.Item("qty") & "-copy(ies)")
End While
conn.Close()
End Sub


     图8

  最后你也许注意到了,表单的底部没有虚拟键盘,如果使用仿真系统,那么这个缺陷就不那么明显,但在使用真实设备并准备输入查询条件的时候,你会感到很为难,不过不用担心我们可以在表单中添加一个菜单条,不过在这之后不要忘记将控件的位置作一些调整。

上一页  1 2 3 4  下一页

【责任编辑:方舟】
【发表评论】【关闭窗口】
■ 相关内容
 设计面向IE for Pocket PC的Web站点
 为Pocket PC上的IE创建ActiveX控件
 Internet Explorer for Pocket PC所支持的Microsoft XML
 Internet Explorer for Pocket PC所支持的Microsoft XML
 从Palm到Pocket PC
 微软Pocket PC又当上了被告
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!