CSCI E-143 CertPrep
Downloadable Code Samples
Fall Term, 2004
for Chapter 5, Data Binding: Reading a Database
for Chapter 6, SQL: DataViewRowState vs. DataRowState
for Chapter 11, Printing:
Dialogs and Controls for Printing
CertPrep Home Page
For those of you with too much time, some zipped files
of working samples of code are available for download.
All the routines work on my machine, and none of them are known to fail on the
machines at 53 Church St. If they don't work on your machine,
for instance because of problems with a database engine, well....
Chapter 5: Data Binding and Reading a Database
Download.
This batch includes the routines I showed in class when we went over
Chapter 5: Data Binding.
Most of this code is described on the page which discusses code for
reading database tables.
Some routines use a database, some don't.
- No database required:
- VerySimpleBinding
- EasySimplePlusComplex
- MiddlinSimplePlusComplexBinding
- Kalani5-6.
This is from pages 367-370 of long Kalani.
You may remember that I was unhappy about the possibility of binding
to an entry in a list box that didn't in fact match.
This is explained on the screen and in the code.
- Database required:
- ClearSQLCode
- CompactSQLCode
- ToolBoxSQL
- TwoListBoxesPlusDataGrid.
Pretty silly.
- TwoRelatedTablesInCode.
- TwoRelatedTablesDrgNDrp.
This one has a bug: the second table won't open when you press
the "+" at the left end of the row in the first table and then click on
the name of the relation.
The bug is explained in the code.
A simple fix will get it to run.
- ComplicatedSimpleAndComplexBinding.
Just about as complicated as I could make it.
Chapter 6: SQL and DataViewRowState vs. DataRowState
Download.
These samples are relevant to each part of Chapter 6,
Consuming and Manipulating Data:
Chapter 6, Part 1
and
Chapter 6, Part 2.
The description of code for
reading database tables
is still relevant.
I only showed the first one of these in class, because I hadn't
put the second one together by then.
- RunSQLQuery. This will let you run ad-hoc
SQL queries against the Northwind database.
It is simple enough, and you should probably have done it
as an exercise, but now you don't have any excuse for not fooling
around with SQL in order to get familiar with it.
There are some sample queries in the
Queries subdirectory,
one of which is surprisingly hard to understand.
- DataViewVsRowState.
This one deals with a couple of the additions to Kalani
that I presented in the second week of Chapter 6.
I wrote it because I was puzzled at the duplication of enumerations.
Well, I'm still puzzled.
The routine was intended to show
- the different uses of the two enumerations for getting at
changed rows in a DataTable:
DataViewRowState and DataRowState.
- the effects of the AcceptChanges,
RejectChanges,
and the Reset commands.
(I think you should understand what these dotheir effect on the
DataSet's description of the DataRows it is holding.)
If you try making changes in the top DataGrid to see them reflected
in the other two, remember that you have to press "Enter"
to get the system to see the changes.
Also notice that the AcceptChanges
command will seem to make changes and additions disappear,
because they are now regarded as "original".
Finally, notice what the
Reset command doessomething
I didn't expect.
There are some other features in this code that might be worth looking at:
- How to obtain all the values of an enumeration
- How to put the enumeration member itself into a combo box,
instead of putting in a line of text and then reconstituting it when
you retrieve comboBox.SelectedItem
- How to get methods to execute when you change things
in a DataSet. Surprisingly difficult: there isn't any
event for "DataRow added".
- The odd fact (frustrating, too):
when you set a DataGrid's DataBinding, the DataGrid
must be enabled. Otherwise, when you enable it and
display it, the vertical scroll bar won't work.
I am not making this up.
Chapter 11: Dialogs and Controls for Printing
Download.
This simple routine,
PrintingTest,
shows the effects of various printing Dialogs and controls,
including the output of the events that occur during printing.
There is a lot of diagnostic Debug output, so be sure to run it under Debug.
Let me know when you find the bugs.
The bugs I already know about I describe in the code.
(There is one case where you have to correct the stated bug
before the routine will work.)
You have to look at the code itself in these samples.
That's the point.
Last revised Dec. 29, 2004