http://www.asp.net/whitepapers/aspnet4#0.2__Toc253429240
Wednesday, 22 February 2012
Thursday, 9 February 2012
Convert dictionary to dataTable in C# ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;
/* calling */
protected void btnSubmit_Click(object sender, EventArgs e)
{
Product objProduct = new Product ();
objProduct.Id = 1;
objProduct.Name = "Computer";
objProduct.Description = "Computer is a electronic machine.";
objProduct.createdDate = System.DateTime.Now;
Dictionary<string, Product> productDictionary = new Dictionary<string, Product>();
productDictionary.Add("1", objProduct);
DataTable RegistrationP= new DataTable ();
RegistrationP = DictionaryToDataTable.ConvertTo<Product>(productDictionary, "DemoTable");
}
/* Product Class */
public class Product
{
public Int16 Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime createdDate { get; set; }
}
/* to Convert Dictionary to DataTable Class */
class DictionaryToDataTable
{
public static DataTable ConvertTo<T>(Dictionary<string, T> list, string dataTableName)
{
DataTable table = CreateTable1<T>(dataTableName);
Type entityType = typeof(T);
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);
foreach (KeyValuePair<string, T> item in list)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
if (prop.PropertyType.Name != "Dictionary`2")
{
if (prop.PropertyType.FullName == "System.String")
if (prop.GetValue(item.Value) == null)
row[prop.Name] = prop.GetValue(item.Value);
else
row[prop.Name] = prop.GetValue(item.Value).ToString().Replace("'", "''");
else
row[prop.Name] = prop.GetValue(item.Value);
}
table.Rows.Add(row);
}
return table;
}
public static DataTable CreateTable1<T>(string dataTableName)
{
Type entityType = typeof(T);
DataTable table = new DataTable(dataTableName);
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);
foreach (PropertyDescriptor prop in properties)
{
table.Columns.Add(prop.Name, prop.PropertyType);
}
return table;
}
}
Hope this helps.
Wednesday, 8 February 2012
What’s the use of smartnavigation property ?
In
earlier versions of ASP.NET, you enable smart navigation by using the
Page.SmartNavigation property. When you set the Page.SmartNavigation
property to true, the following smart navigation features are enabled:
The scroll position of a Web page is maintained after postback.
The element focus on a Web page is maintained during navigation.
The flicker effect is minimized during navigation/postback..
The scroll position of a Web page is maintained after postback.
The element focus on a Web page is maintained during navigation.
The flicker effect is minimized during navigation/postback..
What is the use of finalize method in .net ?
NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources (ex: - Windows API created objects, File, Database connection objects, COM objects, third party control etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Object. Finalize method which can be overridden and clean up code for unmanaged resources can be put in this section.
Monday, 6 February 2012
How to add/replace doublequote in C# ?
string str_Add_Doublequote = "<p style=\"font-size: 10pt; font-family: sans-serif;\"><font class=\"Apple-style-span\" face=\"Tahoma\" size=\"2\"></font></p>";
string _Double_To_Singlequotes = str_Add_Doublequote.Replace("\"", "'");
string _single_To_Doublequotes = _Double_To_Singlequotes.Replace("'", "\"");
Proper case in sql server
create function ProperCase(@Text as varchar(8000))
returns varchar(8000)
as
begin
declare @Reset bit;
declare @Ret varchar(8000);
declare @i int;
declare @c char(1);
select @Reset = 1, @i=1, @Ret = '';
while (@i <= len(@Text))
select @c= substring(@Text,@i,1),
@Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
@Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,
@i = @i +1
return @Ret
end
select dbo.ProperCase('this,my friends, is a test.wHat DO you think?i like shaquile o''neal')
returns varchar(8000)
as
begin
declare @Reset bit;
declare @Ret varchar(8000);
declare @i int;
declare @c char(1);
select @Reset = 1, @i=1, @Ret = '';
while (@i <= len(@Text))
select @c= substring(@Text,@i,1),
@Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
@Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,
@i = @i +1
return @Ret
end
select dbo.ProperCase('this,my friends, is a test.wHat DO you think?i like shaquile o''neal')
Subscribe to:
Posts (Atom)