Posts

Showing posts from December, 2012

shortcut key for \ Backslash

you can generate it by holding ALT + 092

convert Date by Exact Format

To convert Date time by Format string datestring="12/2/2012"; DateTime.ParseExact(datestring, "MM/dd/yyyy", CultureInfo.InvariantCulture);

in clause to match all items

select * from ItemsPackage where ItemId IN (3,5,2) This will be match as OR Expression to make it get ALL item Id you can make it : select PakageId from ItemsPackage where ItemId in (3,5,2) group by PakageId having count(PakageId) = 3 -- Count of In clause (3,5,2)

add days to date Javascript

To add days to javascript use : // days added var days=5; var ms = new Date().getTime() + (86400000 * days); var added = new Date(ms);

Check if variable is 'undefined' or 'null'

to check if javascript variable is undefined or nul use : if(typeof variable_here === 'undefined'){ // your code here. }; OR : if(! variable_here){ // your code here. };

Retrieve Last Inserted Identity

To returns the last IDENTITY value produced on a connection get last Identity your Session added by your Connection if they any trigger add to any other tables it will return it SELECT @@IDENTITY To returns the last IDENTITY value produced on a connection and by a statement in the same scope SELECT SCOPE_IDENTITY() To returns the last IDENTITY value produced in a table it returns the identity value generated for a specific table in any session and any scope SELECT IDENT_CURRENT('tablename') To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Get URL Parameter "Query strings"

to get paraneter from url string Url = "http://localhost:6109/CANSHOP/GenerateCoupons.aspx?CouponId=1&MemberId=4"; Uri tempUri = new Uri(Url); string sQuery = tempUri.Query; var query = HttpUtility.ParseQueryString(sQuery); string cId = query["CouponId"]; string mId = query["MemberId"];

Generate New (uniqueidentifier) in SQL Server

If you want to generate a new uniqueidentifier in SQL you can simply use the NEWID() function -- Example 1 SELECT NEWID() -- Example 2 DECLARE @EmployeeID uniqueidentifier SET @EmployeeID = NEWID() -- Example 3 INSERT INTO Employees(EmployeeID, Name) VALUES (NEWID(), 'msm2020')

Get Page Path Details and URL

if we have URL Like : http://localhost:96/Cambia3/Temp/Test.aspx?q=item#fragment to get App Path: Request.ApplicationPath result : Cambia3 to get App Path with page name: Request.CurrentExecutionFilePath result : Cambia3/Temp/Test.aspx to get page path: Request.FilePath result : Cambia3/Temp/Test.aspx to get path: Request.Path result : Cambia3/Temp/Test.aspx to get local page path: Request.Url.LocalPath result : Cambia3/Temp/Test.aspx to get absolute path: Request.Url.AbsolutePath result : Cambia3/Temp/Test.aspx to get physical path: Request.PhysicalApplicationPath result : D:\Inetpub\wwwroot\CambiaWeb\Cambia3 to get page with query: Request.RawUrl result : Cambia3/Temp/Test.aspx?query=arg to get url with query: Request.Url.PathAndQuery result : Cambia3/Temp/Test.aspx?query=arg to get url: Request.Url.AbsoluteUri result : http://localhost:96/Cambia3/Temp/Tes...
Image
using Google Infographics more details <img src='https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello%20world' /> result :

parsing currency to decimal

best way to convert "$10" to decimal is: decimal d = decimal.Parse("$45.00", NumberStyles.Currency); OR decimal.TryParse("$45.00", NumberStyles.Currency, culture, out d);

List of Class To XML File ,C#

if you create a collection class that have a list of Class Like : public class Foo { public List BarList { get; set; } } public class Bar { public string Property1 { get; set; } public string Property2 { get; set; } } we can use XmlSerializer to Save Collection to XML File Foo f = new Foo(); f.BarList = new List (); f.BarList.Add(new Bar { Property1 = "abc", Property2 = "def" }); XmlSerializer ser = new XmlSerializer(typeof(Foo)); using (FileStream fs = new FileStream(@"c:\sertest.xml", FileMode.Create)) { ser.Serialize(fs, f); }

XML to List of Class C#

if we have XML file like this : <picturecollection> <photo> <name>One</name> <path>somepath1</path> </photo> <photo> <name>Two</name> <path>somepath2</path> </photo> </picturecollection> we can use This Code to return List of Class XDocument xdoc = XDocument.Load(Server.MapPath(@"\Photo.xml")); List pics = (from xml in xdoc.Elements("PictureCollection").Elements("Photo") select new Pic { PicName = xml.Element("name").Value, TbPath = xml.Element("path").Value }).ToList(); public class Pic { public string PicName {get; set;} public string TbPath { get; set; } }