sum of a column in datatable c#

Filed in Uncategorized Leave a comment

DataTable table;
table = ds.Tables["Ordertable"]
Double dblTotalCost = Convert.ToDouble(table.Compute(“SUM(SalesPriceMoney)”, “”));
if (dblTotalCost > 0)
lblTotalCost.Text = dblTotalCost.ToString(“C”);
else
lblTotalCost.Text = “$0.00″;

Split each email address seperated by semi colon

Filed in Uncategorized Leave a comment

MailMessage mm = new MailMessage();
string strEmails = “abcccs22@domain.com; sd22321@gasd3mail.com; s2s33@gdasdsdmail.com;”;

string[] emails = strEmails.Split(‘;’);
foreach (string email in emails)
{
if (email.Trim() != string.Empty)
{
mm.ReplyToList.Add(new MailAddress(email));
}
}

Configuring Microsoft Team Foundation Server 2012

Filed in .Net Leave a comment

Today I have configured Microsoft Team Foundation Server 2012 for one of my newly started VS project. Looks promising product for every stakeholder of the project. My focus is mainly on code maintainability, task assignment and its management. Below are some useful links.

Using TFS
http://msdn.microsoft.com/en-US/library/ms181368.aspx

Optimize your folder names
http://msdn.microsoft.com/en-US/library/ms181378.aspx

Set Up Your Dev Machine and Start Using Version Control
http://msdn.microsoft.com/en-US/library/ms181384.aspx

Add Files to the Server or Add Project/ Solution to TFS
http://msdn.microsoft.com/en-US/library/ms245454.aspx#add_existing_project

Check In Your Work to the Team’s Codebase
http://msdn.microsoft.com/en-US/library/ms181407.aspx

Resolve File Conflicts
http://msdn.microsoft.com/en-US/library/ms181432.aspx

how to get row index in DragDrop event of datagridview

Filed in .Net Leave a comment

http://stackoverflow.com/questions/1835329/how-to-target-a-datagridview-row-or-cell-from-dragdrop-event

Finding number of occurrence of a character in SQL

Filed in SQL Leave a comment

declare @myvar varchar(20)
set @myvar = ’H—el-lo -Wo-r-l-d’
select len(@myvar) - len(replace(@myvar,’-',”))
Result: 8

exception logging block not logging with correct datetime

Filed in .Net Leave a comment

In app.config change {timestamp} to {timestamp(local)}

http://stackoverflow.com/questions/4561303/enterprise-library-5-0-application-logging-incorrect-datetime

Activation error occurred while trying to get instance of type Database, key “KEYNAME”

Filed in .Net 2 Comments

In my case  providerName=”System.Data.SqlClient” tag is missing from connection string

<add name=”KEYNAME” connectionString=”Data Source=.\SQLEXPRESSR2;Initial Catalog=DBNAME;Integrated Security=False; User ID=userid;Password=password; Max Pool Size=500″ providerName=”System.Data.SqlClient“/>

Below is from more error log

Type :Microsoft.Practices.ServiceLocation.ActivationException
Original Message : Activation error occured while trying to get instance of type Database, key “<KEYNAME>”
Source :Microsoft.Practices.ServiceLocation
Stack Trace : at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String name)
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(String name)

Inner Exception Message is :Resolution of the dependency failed, type = “Microsoft.Practices.EnterpriseLibrary.Data.Database”, name = “<KEYNAME>”.
Exception occurred while: while resolving.
Exception is: InvalidOperationException – The type Database cannot be constructed. You must configure the container to supply this value.
———————————————–
At the time of the exception, the container was:

Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,<KEYNAME>

Inner Exception Stack Trace is : at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)

Make a new column in datatable c# using existing columns or hardcode values, using expression

Filed in .Net Leave a comment

Merge two or more columns in c# datatable

ds.Tables[1].Columns.Add(“NEWCOLUMNNAME”, typeof(System.String), “COL1+ ‘-’ + COL2″);

You can make any complex sql expression.

Recover MS Office files if you mistakenly press “No” when asked to save.

Filed in OS Leave a comment

Below is the path form where you can recover auto saved copy of office files. It is very helpful if you mistakenly press “No” on close dialogue.

C:\Users\<UserName>\AppData\Local\Microsoft\Office\UnsavedFiles

PTCL Freedom Unlimited Package in comparison with Double Up Unlimited Package

Filed in Uncategorized Leave a comment

Below is the analysis on new PTCL Freedom Unlimited Package in comparison with old Double Up Unlimited Package. I did it for the DSL subscribers and obviously some plus and minus are possible in it.

With 1 MB DSL 

Total Bill Rs. 1750: New Package with 1 MB DSL (1200 DSL, 250 Fixed, 300 Tax approx)
Total Bill Rs. 2200: New Package with 1 MB DSL and (Smart TV RS.449)
Total Bill Rs. 2330: Double Up Package charges for same

With 2 MB DSL 

Total Bill Rs. 2050: New Package with 2 MB DSL (1500 DSL, 250 Fixed, 350 Tax approx)
Total Bill Rs. 2500: New Package with 2 MB DSL and (Smart TV RS.449)
Total Bill Rs. 2650: Double Up Package charges for same

Smart TV facility charges is free in Double up package and if you are paying any device charges that would be added in the above amount. PCTL to PTCL Local, Nation wide and Vfone calls are unlimited in the above packages. Standard rates would apply for the calls on Mobile, International or any other network. The only draw back of this new Freedom Unlimited Package is that cell phone calls from your land line in Double Up Unlimited package is half rated from standard. But you can add Mobile bundle package with it.

Be aware !!! Once you opt for this new package you can’t come back to Double Up Unlimited package.

There is some thing good for the simple land line customers also (without DSL)  who do PCTL to PTCL Local, Nation wide and Vfone calls. Around in Rs 700 you can do it unlimited.

P.S: I tried my best in calculating above rate but I am not responsible for any any mistake in above calculation.

Referene: PTCL official website

TOP