Developing Pocket PC Apps with SQL Server CE
Pages: 1, 2, 3, 4, 5, 6
As usual, when a title is selected, more information about the selected title is displayed in the label controls:
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
Figure 6: Displaying information about the title selected
To place an order for a bookstore, specify the quantity and click on the Add button. An order for the bookstore selected will be added:
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
And a message box confirms the addition:
Figure 7: Confirming the addition
Checking the Orders
Clicking on the second tabpage displays the orders made by bookstores. When the Refresh button is clicked, the first ListBox control will display the list of bookstores available:
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

