Wednesday, November 18, 2009
jQuery datepicker control on ASP.NET (controls).
http://blog.vanmeeuwen-online.nl/2009/10/easy-way-to-use-jquery-datepicker-on.html
Saturday, November 7, 2009
Sunday, November 1, 2009
setting app.config for different environments
Interesting way of seperating development and production configuration files.
I haven't tested this with web.config file.
Click here
I haven't tested this with web.config file.
Click here
DataGridView - Sum of a Column using LINQ - Windows Forms
You can use this one liner using LINQ instead of looping throw DataGridView Rows.
DataView view = adventureWorksDataSet.Tables[0].DefaultView ;
// view.RowFilter = "Included = true";
// LINQ Sum: 152.1
decimal total = view.Cast().Sum(row => (Int32)row["EmployeeID"]);
// LINQ count: 2 (to prove we have exluded the one row)
int count = view.Cast().Count();
DataView view = adventureWorksDataSet.Tables[0].DefaultView ;
// view.RowFilter = "Included = true";
// LINQ Sum: 152.1
decimal total = view.Cast
// LINQ count: 2 (to prove we have exluded the one row)
int count = view.Cast
C# - Converting DataGridView to DataSet - Windows Forms
public System.Data.DataSet DatagridviewToDataset(DataGridView dgv)
{
System.Data.DataSet ds = new System.Data.DataSet();
//Take the data and structure from the datagridview and return it as a dataset. You can use
//"Imports System.Data" declaration at the top of your project/class and remove the system.data
//from the various parts of this function.
try {
//Add a new table to the dataset
ds.Tables.Add("Main");
//Add the columns
System.Data.DataColumn col = default(System.Data.DataColumn);
//For each colum in the datagridveiw add a new column to your table
foreach (DataGridViewColumn dgvCol in dgv.Columns) {
col = new System.Data.DataColumn(dgvCol.DataPropertyName);
ds.Tables["Main"].Columns.Add(col);
}
//Add the rows from the datagridview
System.Data.DataRow row = default(System.Data.DataRow);
int colcount = dgv.Columns.Count - 1;
for (int i = 0; i <= dgv.Rows.Count - 1; i++) {
row = ds.Tables["Main"].Rows.Add();
foreach (DataGridViewColumn column in dgv.Columns) {
row[column.Index] = dgv.Rows[i].Cells[column.Index].Value;
}
}
return ds;
}
catch (Exception ex) {
//Catch any potential errors and display them to the user
MessageBox.Show("Error Converting from DataGridView " + ex.Message);
return null;
}
}
{
System.Data.DataSet ds = new System.Data.DataSet();
//Take the data and structure from the datagridview and return it as a dataset. You can use
//"Imports System.Data" declaration at the top of your project/class and remove the system.data
//from the various parts of this function.
try {
//Add a new table to the dataset
ds.Tables.Add("Main");
//Add the columns
System.Data.DataColumn col = default(System.Data.DataColumn);
//For each colum in the datagridveiw add a new column to your table
foreach (DataGridViewColumn dgvCol in dgv.Columns) {
col = new System.Data.DataColumn(dgvCol.DataPropertyName);
ds.Tables["Main"].Columns.Add(col);
}
//Add the rows from the datagridview
System.Data.DataRow row = default(System.Data.DataRow);
int colcount = dgv.Columns.Count - 1;
for (int i = 0; i <= dgv.Rows.Count - 1; i++) {
row = ds.Tables["Main"].Rows.Add();
foreach (DataGridViewColumn column in dgv.Columns) {
row[column.Index] = dgv.Rows[i].Cells[column.Index].Value;
}
}
return ds;
}
catch (Exception ex) {
//Catch any potential errors and display them to the user
MessageBox.Show("Error Converting from DataGridView " + ex.Message);
return null;
}
}
Subscribe to:
Posts (Atom)