using MyCompany.Business.MyBiz; namespace MyCompany.WinUI.MyUI { public class MyForm : MyBaseForm { private long CustomerKey; private MyDataSet dsData; private MyBizCustomer oBiz; public MyForm(long key) { this.CustomerKey = key; InitializeComponent(); this.FillData(); } public void FillData() { // To simplify, I'm directly calling a Biz class. // In reality, I use a Web Service here instead // which in turn calls the Biz class. oBiz = new MyBizCustomer(); dsData = oBiz.GetCustomer(this.CustomerKey); } } }Now in your MyBiz project, you'd have a Biz class:
using MyCompany.DataAccess.MyDataAccess namespace MyCompany.Business.MyBiz { public class MyBizCustomer { private MyDataSet dsData; public MyDataSet GetCustomer(long CustomerKey) { MyDataAccessCustomer oDA = new MyDataAccessCustomer(); this.dsData = oDA.GetCustomer(CustomerKey); // if you have other Biz things to do to this customer // do it here before returning the DataSet return this.dsData; } } }And, lastly, in your MyDataAccess project, you'd have this class:
namespace MyCompany.DataAccess.MyDataAccess { public class MyDataAccessCustomer { public MyDataSet GetCustomer(long CustomerKey) { // Here's where you'd put all the SqlCommand and DataAdapter stuff // and fill your DataSet. return dsData; } } }Now, a word or two about DataBinding. This is what makes using DataSets worthwhile. When you bind all your TextBox objects to a DataSet, when the user is done entering data and wants to save, you simply call Save method of your Business class (or, as I mentioned in the beginning, the Save method in your Web Service, which calls the Save method in your Business class), which calls the Save method in your DataAccess class which is the ONLY class that actually talks to the database. The DataSet is passed to these calls and the DataAccess class takes the changed data and makes the appropriate calls to the database.
MyTextBox.DataBinding.Add("Text", MyDataSet.Tables["MyTable"], "MyColumn");Although, I've sub-classed all my base controls and included a DataBind method in each one. Here's a sample for my TextBox subclass:
public virtual void DataBind(System.Data.DataTable Data, string Path) { for (int i = 0; i < this.DataBindings.Count; i++) { if (this.DataBindings[i].Equals(this.oBinding)) { this.DataBindings.Remove(this.oBinding); break; } } this.Text = ""; this.m_BoundTable = Data; this.m_BoundColumn = Path; this.oBinding = new Binding(this.m_BoundProperty, Data, Path); this.oBinding.Format += new ConvertEventHandler(this.FormatHandler); this.oBinding.Parse += new ConvertEventHandler(this.ParseHandler); this.DataBindings.Add(this.oBinding); }Hopefully, this will give you a lot of "food for thought".