Sunday, December 28, 2008

Creating CSV file using Oledb object in C#.net

OleDbConnection OleDbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strCSVPath + ";Extended Properties=\"text;HDR=Yes;FMT=Delimited(,)\"");
OleDbCmd = new OleDbCommand("Create table BundlesTable.csv(ProjectName varchar(250),BundleName varchar(250),BundleItems varchar(250))", OleDbCon);
OleDbCmd.ExecuteNonQuery();

Friday, November 21, 2008

Opening the link or website in .net windows application

System.Diagnostics.Process.Start("http://decidyn.com");

Tuesday, November 4, 2008

Converting String to Datetime in C#.net 2.0

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US", false);
culture.DateTimeFormat.DateSeparator = string.Empty;
culture.DateTimeFormat.ShortDatePattern = "yyyyMMdd";

dateime dt=DateTime.ParseExact(startEndDate[1].ToString(),"yyyyMMdd", culture)

Thursday, October 16, 2008

Getting Unique field of a column form a table( also get distinct count of column of datatable)

public DataTable SelectDistinct(string TableName, DataTable SourceTable, string FieldName)
{
DataTable dt = new DataTable(TableName);
dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType);

object LastValue = null;
foreach (DataRow dr in SourceTable.Select("", FieldName))
{
if (LastValue == null || !(ColumnEqual(LastValue, dr[FieldName])))
{
LastValue = dr[FieldName];
dt.Rows.Add(new object[] { LastValue });
}
}
//if (ds != null)
// ds.Tables.Add(dt);
return dt;
}
private bool ColumnEqual(object A, object B)
{

// Compares two values to see if they are equal. Also compares DBNULL.Value.
// Note: If your DataTable contains object fields, then you must extend this
// function to handle them in a meaningful way if you intend to group on them.

if (A == DBNull.Value && B == DBNull.Value) // both are DBNull.Value
return true;
if (A == DBNull.Value || B == DBNull.Value) // only one is DBNull.Value
return false;
return (A.Equals(B)); // value type standard comparison
}