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;
}
}
Saturday, October 31, 2009
changing settings.settings connectionstring.
--I have used this class to avoid changnig connectionstring whenever i need to deploy project into production.
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
namespace yournamespacesame.Properties {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
this["ConnectionString"] = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
namespace yournamespacesame.Properties {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
this["ConnectionString"] = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}
Wednesday, August 19, 2009
Friday, July 24, 2009
Visual Studio 2008 to 2005 downgrade utility
I found a utilty which can convert solution and project files.
http://mises.org/Community/blogs/misestech/archive/2008/02/28/visual-studio-2008-to-2005-downgrade-utility.aspx
But it is not converting class properties.
http://mises.org/Community/blogs/misestech/archive/2008/02/28/visual-studio-2008-to-2005-downgrade-utility.aspx
But it is not converting class properties.
Tuesday, July 14, 2009
Bulk insert a file with Header and Footer
I have a file like the following with Header and Footer.
HDR|20090713014036|4
1|Peter|Junkins|1/12/2005|Dallas|TX|75252
2|David|Junkins|10/12/1999|Dallas|TX|75080
3|John|Sexton|1/12/1990|Dallas|TX|75753
4|Jack|Bill|1/1/1990|Dallas|TX|75252
FTR
I tried to used bulk insert task in DTS using FirstRow and LastRow Attributes. But It is not working as I thought it would work.
1. If I use FirstRow=2 LastRow=5 it fails with the following error.
"Bulk Insert: Unexpected end-of-file (EOF) encountered in data file."
2. If I use FirsRow=2 LastRow=4 It works but Last data row is not loaded
Just for testing I tested with the following scenario. It worked.
3.change footer to FTR|||||| and FirstRow=2 and LastRow=5. It works.
Conclusions:
1. Bulk insert can be used only when all the rows have same number of fields/columns
2. Regular DTS with Transformations works fine. It ignores footer row.
3. Bulk Insert cares about the row after the LASTROW mentioned in the attributes. I don't why????????????????
HDR|20090713014036|4
1|Peter|Junkins|1/12/2005|Dallas|TX|75252
2|David|Junkins|10/12/1999|Dallas|TX|75080
3|John|Sexton|1/12/1990|Dallas|TX|75753
4|Jack|Bill|1/1/1990|Dallas|TX|75252
FTR
I tried to used bulk insert task in DTS using FirstRow and LastRow Attributes. But It is not working as I thought it would work.
1. If I use FirstRow=2 LastRow=5 it fails with the following error.
"Bulk Insert: Unexpected end-of-file (EOF) encountered in data file."
2. If I use FirsRow=2 LastRow=4 It works but Last data row is not loaded
Just for testing I tested with the following scenario. It worked.
3.change footer to FTR|||||| and FirstRow=2 and LastRow=5. It works.
Conclusions:
1. Bulk insert can be used only when all the rows have same number of fields/columns
2. Regular DTS with Transformations works fine. It ignores footer row.
3. Bulk Insert cares about the row after the LASTROW mentioned in the attributes. I don't why????????????????
Subscribe to:
Posts (Atom)