Archive for April, 2008

Where is the data?

April 17, 2008

This may sound stupid , but I had a SQL Lite database in a Winforms project, and I was editing it as I debugged my application, but every time I looked at the actual data in the table I had just edited using the Visual Studio (3.5) preview data function, the data I had just added was nowhere to be found.

It turned out that when I debugged, Visual Studio copied the database over the bin/debug/App_Data/db.mdf file, and whatever changes I made from debug run to debug run were lost.

I just didn’t know it worked that way.

Refreshing DataBound controls in Winforms

April 17, 2008

In a Winforms application (.Net 2.0), I added some data to a table, and I wanted to refresh a combo box after clicking the Add button.


I couldn’t remember how to do it.

Perhaps because the controls related to data access and data binding are so complex it took me longer to remember how to do it.

Databinding Winforms Refresh


It turns out, the only command you need is “Fill”

ret = DataLayer.Chunk_Add(this.txtTitle.Text, txtChunkHeader.Text, txtChunkItem.Text, txtChunkFooter.Text); this.chunksTableAdapter.Fill(this.dsDataGoop.Chunks);


I had some trouble just using the insert method from the table adapter on the page, and I added the data with:

public static int Chunk_Add(string sTitle, string sHeader, string sItem, string sFooter) { dsDataGoopTableAdapters.ChunksTableAdapter da = new dsDataGoopTableAdapters.ChunksTableAdapter(); int ret; try { da.Connection.Open(); ret = da.Insert(sTitle, sHeader, sItem, sFooter, DateTime.Now); da.Connection.Close(); } catch (Exception e) { System.Diagnostics.Debug.Print(e.Message); return -1; } return ret; }