Saturday, 29 August 2009

Smart Device part 4

View the data

 
create a new form add a data grid and leave the name to the default
paste this code
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As System.Data.SqlServerCe.SqlCeConnection
Dim cmd As System.Data.SqlServerCe.SqlCeCommand
Dim SQL As String
Dim dt As System.Data.DataTable
Dim da As System.Data.SqlServerCe.SqlCeDataAdapter
Try
' Open the database.
cn = New System.Data.SqlServerCe.SqlCeConnection(connstr)
cn.Open()
' Retrieve the customers
SQL = "SELECT * FROM customers"
cmd = New System.Data.SqlServerCe.SqlCeCommand(SQL, cn)
dt = New DataTable
da = New SqlCeDataAdapter
da.SelectCommand = cmd
da.SelectCommand.Connection = cn
da.Fill(dt)
DataGrid1.DataSource = dt
'MessageBox.Show(CStr(DataGrid1.VisibleRowCount))
DataGrid1.ColumnHeadersVisible = True
cn.Close()
Catch sqex As System.Data.SqlServerCe.SqlCeException
MessageBox.Show(sqex.ToString(), "DB operation failed")
End Try
End Sub
To make the form close add a menu and name it close type this code
me.close
to enable the user to show this form go back to the main form add a new menu and name it show customers
double click it and paste this code
Dim f2 As New Form2
f2.ShowDialog()
This is it
you can use this code to make much more intresting applications for pocket pc

No comments:

Post a Comment

Reset numbering for Screenshots Win+PrtSc

I was using today the screen shot functionality of Windows 8.1 Win Key + PrtSc How to reset the numbering?