Search This Blog

Sunday, May 20, 2007

Sample Code Adding Image control to FlowLayoutPanel


Example Code to Dynamically add Picturebox to a FlowLayoutPanel.

PictureBox pBox = new PictureBox();
pBox.ImageLocation = "C:\\Images\\Collages\\Faces.jpg";
pBox.SizeMode = PictureBoxSizeMode.Zoom;
pBox.Location = new Point(0, 0);
pBox.Height = 50;
pBox.Width = 50;
flowLayoutPanel1.Controls.Add(pBox);

Sunday, May 6, 2007

ADO.NET Data Binding Examples

An example shows how you can create a DataTableReader and bind it to a DataGridView

using (SqlConnection cn = new SqlConnection(cnStr)) {
SqlCommand cmd = new SqlCommand(sqlAllCustomers, cn); SqlDataAdapter adpt = new
SqlDataAdapter(cmd); DataTable dtCustomers = new DataTable("Customers");
adpt.Fill(dtCustomers); DataTableReader dtRdr = ds.CreateDataReader();
dgvCustomers.DataSource = dtRdr;
}


Load method of a DataSet or a DataTable, you can pass in a DataTableReader or any reader class that implements the IDataReader interface.

DataTableReader dtRdr = dt1.CreateDataReader();
DataTable dt2 = new DataTable();
dt2.Load(dtRdr);


DataSet can be filled from the Products table of the Northwind database.
string sSQL = "SELECT * FROM Products";
string sConnString = "Server=(local);Database=Northwind;Integrated Security=SSPI;";
SqlDataAdapter oDa = new SqlDataAdapter();
DataSet oDs = new DataSet();
using(SqlConnection oCn = new SqlConnection(sConnString))
{
SqlCommand oSelCmd = new SqlCommand(sSQL, oCn);
oSelCmd.CommandType = CommandType.Text;
oDa.SelectCommand = oSelCmd; oDa.Fill(oDs, "Products");
}