Thursday, November 22, 2012

BCP command for Data moving from SQL server to SQL Azure


For making sql  tables to text data files at local drive

bcp databasename.dbo.Client out E:\Shergroup\SqlData\MoveDataFromSQLAzure.txt -c -U sa -S sherbasefive -P 12456

rk5n5pqf6u.database.windows.net


for coping from local dive text data files to sql azure

bcp databasename.dbo.Client in  E:\Shergroup\SqlData\MoveDataFromSQLAzure.txt -c -U myadmin@rk5n5p -S tcp:rk5n5p.database.windows.net -P c0r=jdb

Wednesday, November 21, 2012

highlighting gridview column cell color in asp.net



protected void GDVHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string amtsigh = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Payment_Amt"));
            string minus = amtsigh.Substring(0, 1);
            if (minus == "-")
            {
                e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
            }

        }
    }

Friday, November 9, 2012

Adding new line after 5 items in list and returning in string using asp.net


1.call method
string PagesNames2 = Convert.ToString( ReturnArrayList(PagesNamesExist));

2.Here is the menthod that adds line break after 5 items

int cnt = 0;
    int warrantIDInt = 0;
    public StringBuilder ReturnArrayList(StringBuilder sb)
    {
        StringBuilder warrantId = new StringBuilder();
        ArrayList warrantIDList = new ArrayList();
        string[] ArryayPageId = sb.ToString().Split(',');
        if (ArryayPageId.Length > 1)
        {
            foreach (string id in ArryayPageId)
            {
                warrantIDList.Add(id);
            }
        }
                         

        if (warrantIDList.Count > 5)
        {
            for (int i = 0; i < warrantIDList.Count; i++)
            {
                string warrantIDStr = warrantIDList[i].ToString();
               
             
                warrantId.Append(warrantIDStr + ",");
                cnt++;
                if (cnt > 5)
                {
                    warrantId.Append("<br/>");
                    cnt = 0;
                }
            }
        }
        else
        {
            for (int i = 0; i < warrantIDList.Count; i++)
            {
                string warrantIDStr = warrantIDList[i].ToString();
                warrantId.Append(warrantIDStr + ",");
            }
        }
        return warrantId;
    }

Thursday, November 1, 2012

How to get selected items value from listbox in c#


if (ListBox1.Items.Count > 0)
        {
            for (int i = 0; i < ListBox1.Items.Count; i++)
            {
                if (ListBox1.Items[i].Selected)
                {
                    string selectedItem = ListBox1.Items[i].Text;
                    //insert command
                }
            }
        }

Friday, October 26, 2012

How to get page name from URL in c#


this.GetType().Name.Split('_')[0]
Or
this.GetType().Name
or
public string GetCurrentPageName() 
{ 
    string sPath = Request.Url.AbsolutePath;
    System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
    string sRet = oInfo.Name; 
    return sRet; 
}

Thursday, October 25, 2012

How to clear Cache on logout in c#


Call this method on page load for clearing cache

 public void ClearApplicationCache()
    {
        List<string> keys = new List<string>();

        IDictionaryEnumerator enumerator = Cache.GetEnumerator();

        while (enumerator.MoveNext())
        {
            keys.Add(enumerator.Key.ToString());
        }

        for (int i = 0; i < keys.Count; i++)
        {
            Cache.Remove(keys[i]);
        }
    }

Monday, October 22, 2012

Caching in ASP.NET using c#

Caching is the ability to store page output and data in memory for the first time it is requested and later we can quickly retrieve them for multiple, repetitious client requests. It is like keeping a copy of something for later use, so we can reduce the load factor on Web servers and database servers by implementing caching on a Web application.

Add dataset to cache....

Cache.Add("dataset", dataset, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 0, 60), System.Web.Caching.CacheItemPriority.Default, null);



Now how to use cache dataset in any page of application

DataSet ds = new DataSet();
ds = (DataSet) Cache["dataset"];