SQLServer datatype CLRdatatype(SQLServer) CLRdatatype(.NET Framework)
varbinary SqlBytes, SqlBinary Byte[]
binary SqlBytes, SqlBinary Byte[]
varbinary(1), binary(1) SqlBytes, SqlBinary byte, Byte[]
image None None
varchar None None
char None None
nvarchar(1), nchar(1) SqlChars, SqlString Char, String, Char[]
nvarchar SqlChars, SqlString String, Char[]
nchar SqlChars, SqlString String, Char[]
text None None
ntext None None
uniqueidentifier SqlGuid Guid
rowversion None Byte[]
bit SqlBoolean Boolean
tinyint SqlByte Byte
smallint SqlInt16 Int16
int SqlInt32 Int32
bigint SqlInt64 Int64
smallmoney SqlMoney Decimal
money SqlMoney Decimal
numeric SqlDecimal Decimal
decimal SqlDecimal Decimal
real SqlSingle Single
float SqlDouble Double
smalldatetime SqlDateTime DateTime
datetime SqlDateTime DateTime
sql_variant None Object
User-defined type(UDT) None user-defined type
table None None
cursor None None
timestamp None None
xml SqlXml None
Thursday, 28 February 2013
SQL Server Data Types and Their .NET Framework Equivalents
Monday, 19 November 2012
Get Assembly location of the DLL added to SQL Server
SELECT
assembly = a.name,
path = f.name
FROM sys.assemblies AS a
INNER JOIN sys.assembly_files AS f
ON a.assembly_id = f.assembly_id
WHERE a.is_user_defined = 1;
Thursday, 8 November 2012
Get GridView Column Headers and Appropriate Row Values in Asp.Net
Get Gridview column header(s) text and Specific Row's Values on Row Command in asp.net. Below Method takes GridView control, Command Source Within the Row(LinkButton, Button, ImageButton, etc..), no of Columns to skip in from Start Column and from End Column as Parameters and returns List<KeyValuePair<headerText,Values>> as output.
private void SetDeleteDetails(GridView pGV, object pCmdSource, int pStartSkipColCount=0, int pEndSkipColCount=0)
{
List<KeyValuePair<string, string>> lkvp = new List<KeyValuePair<string, string>>();
GridViewRow rw = (GridViewRow)((Control)pCmdSource).NamingContainer;
for (int i = pStartSkipColCount; i < pGV.Columns.Count - pEndSkipColCount; i++)
if (!string.IsNullOrEmpty(rw.Cells[i].Text))
lkvp.Add(new KeyValuePair<string, string>(pGV.Columns[i].HeaderText, rw.Cells[i].Text));
//Session["DeleteDetails"] = lkvp;
}
Labels:
.Net,
ASp.Net,
C#,
CommandArgument,
GridView,
GridViewRowCommand
Wednesday, 7 November 2012
Get Specific Property Name Using Expression
Hope the program explains all:
class Program
{
static void Main(string[] args)
{
SomeClass sc = new SomeClass();
Console.WriteLine(sc.p1.GetType());
//RemoteMgr.ExposeProperty(() => SomeClass.SomeProperty);
MemberInfo member = RemoteMgr.GetMemberInfo((SomeClass p) => p.SomeProperty);
Console.WriteLine(member.Name);
Console.ReadKey();
}
}
public class SomeClass
{
public string SomeProperty
{
get { return "Foo"; }
}
}
public class RemoteMgr
{
public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T,U>> expression)
{
var member = expression.Body as MemberExpression;
if (member != null)
return member.Member;
throw new ArgumentException("Expression is not a member access", "expression");
}
}
Monday, 22 October 2012
Raising a Button Click Event Programmatically
You can use the following C# code raise the event:
((IPostBackEventHandler)Button1).RaisePostBackEvent(null);
This code will raise the button-click event for Button1 just as though the user clicked the button. Since we are passing a null as the EventArgs for the event, the registered methods must not attempt to do anything with it. Or, you could create an EventArgs object and pass it.
There is at least one other approach using reflection, but I think the technique above is the cleaner way to do this.
Labels:
.Net,
ASp.Net,
AutoPostBack,
C#,
Control Events,
Controls
Monday, 8 October 2012
Understanding ASP.NET View State
Introduction
Microsoft® ASP.NET view state, in a nutshell, is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. In my experiences as a trainer and consultant, view state has caused the most confusion among ASP.NET developers. When creating custom server controls or doing more advanced page techniques, not having a solid grasp of what view state is and how it works can come back to bite you. Web designers who are focused on creating low-bandwidth, streamlined pages oftentimes find themselves frustrated with view state, as well. The view state of a page is, by default, placed in a hidden form field named
__VIEWSTATE
. This hidden form field can easily get very large, on the order of tens of kilobytes. Not only does the __VIEWSTATE
form field cause slower downloads, but, whenever the user posts back the Web page, the contents of this hidden form field must be posted back in the HTTP request, thereby lengthening the request time, as well.
This article aims to be an in-depth examination of the ASP.NET view state. We'll look at exactly what view state is storing, and how the view state is serialized to the hidden form field and deserialized back on postback. We'll also discuss techniques for reducing the bandwidth required by the view state.
Note This article is geared toward the ASP.NET page developer rather than the ASP.NET server control developer. This article therefore does not include a discussion on how a control developer would implement saving state. For an in-depth discussion on that issue, refer to the book Developing Microsoft ASP.NET Server Controls and Components.
Before we can dive into our examination of view state, it is important that we first take a quick moment to discuss the ASP.NET page life cycle. That is, what exactly happens when a request comes in from a browser for an ASP.NET Web page? We'll step through this process in the next section.
Tuesday, 14 August 2012
Simple Business Rules Engine
Rules Engine is a . NET C# project that validates business logic by defining a bunch of rules for your data classes. Rules are defined using a fluent-interface (fluent validation) helper class, and not by decorating your existing objects with attributes, therefore de-coupling validation logic from data (or domain) classes.
Features
- Rules are inheritable. Defining RuleX for TypeA will also apply to TypeB (given that TypeB inherits from Type A)
- Rules are extensible. Creating custom rules are only a matter of implementing an interface.
- Conditional validation. When defining rules, it is possible to have different rules given different conditions. E.g. Not Null Rule only applies to FieldA when FieldB > 100
- Cross-Field validation. Defining a rule that FieldA must be greater than FieldB comes very naturally with the fluent-interface helper class.
- Fluent-Interface. Adding rules to objects is done by a fluent-interface helper class.
- Error Messages. Defining error messages can be done at the same time as defining your rules (Or separately). They can apply to the Class, A Property of that class, or a Rule for that property.
Below is the simple example for rules engine:
public class Person { public string Name { get; set; } public string Phone { get; set; } public DateTime DateOfBirth { get; set; } } public class Program { public static void Main(string[] args) { Engine engine = new Engine(); engine.For<Person>() .Setup(p => p.DateOfBirth) .MustBeLessThan(DateTime.Now) .Setup(p => p.Name) .MustNotBeNull() .MustMatchRegex("^[a-zA-z]+$") .Setup(p => p.Phone) .MustNotBeNull() .MustMatchRegex("^[0-9]+$"); Person person = new Person(); person.Name = "Bill"; person.Phone = "1234214"; person.DateOfBirth = new DateTime(1999, 10, 2); bool isValid = engine.Validate(person); } }
Please Follow the Following LInk for downloading Rules Engine http://rulesengine.codeplex.com/
Labels:
.Net,
C#,
Expressions,
Rules Engine,
Validation Engine
Subscribe to:
Posts (Atom)