RSS

Author Archives: Anil Shah

Partial Classes in C# And VB.net

Partial Class

In this article I will explain what is a partial class? What are the benefits of using partial classes

It is possible to split the definition of a class or a struct, or an interface over two or more source files. Each source file contains a section of the class definition, and all parts are combined when the application is compiled.

When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.

When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.

Benefit of partial classes:

1) More than one developer can simultaneously write the code for the class.

2) You can easily write your code (for extended functionality) for a VS.NET generated class. This will allow you to write the code of your own need without messing with the system generated code.

There are a few things that you should be careful about when writing code for partial classes:

  • All the partial definitions must proceeded with the key word “Partial”.
  • All the partial types meant to be the part of same type must be defined within a same assembly and module.
  • Method signatures (return type, name of the method, and parameters) must be unique for the aggregated typed (which was defined partially).
  • The partial types must have the same accessibility.
  • If any part is sealed, the entire class is sealed.
  • If any part is abstract, the entire class is abstract.
  • Inheritance at any partial type applies to the entire class.
 
Leave a comment

Posted by on November 11, 2013 in ASP.NET

 

update table with male to female And female to male OR Swap Value of Column Without Case Statement

Just for clarity I am involving the original problem statement here.

USE tempdb
GO
CREATE TABLE SimpleTable (ID INT, Gender VARCHAR(10))
GO
INSERT INTO SimpleTable (ID, Gender)
SELECT 1, 'female'
UNION ALL
SELECT 2, 'male'
UNION ALL
SELECT 3, 'male'
GO
SELECT *
FROM SimpleTable
GO
-- Insert Your Solutions here
-- Swap value of Column Gender
SELECT *
FROM SimpleTable
GO
DROP TABLE SimpleTable
GO

Solution No 1.

UPDATE S
SET S.Gender = D.Gender
FROM SimpleTable S
INNER JOIN SimpleTable D
ON S.Gender != D.Gender

Solution No 2.

CREATE TABLE #temp(id INT, datacolumn CHAR(4))
INSERT INTO #temp
VALUES(1,'gent'),(2,'lady'),(3,'lady')
DECLARE @value1 CHAR(4), @value2 CHAR(4)
SET @value1 = 'lady'
SET @value2 = 'gent'
UPDATE #temp
SET datacolumn = REPLACE(@value1 + @value2,datacolumn,'')

Solution No 3.

UPDATE SimpleTable
SET Gender = RIGHT(('fe'+Gender), DIFFERENCE((Gender),SOUNDEX(Gender))*2)

Solution No 4.

UPDATE St
SET St.Gender = t.Gender
FROM SimpleTable St
CROSS Apply (SELECT DISTINCT gender FROM SimpleTable
WHERE St.Gender != Gender) t

Solution No 5.

UPDATE SimpleTable
SET Gender=X.NewGender
FROM (VALUES('male','female'),('female','male')) AS X(OldGender,NewGender)
WHERE SimpleTable.Gender=X.OldGender

I hope this helps, good luck!

 
Leave a comment

Posted by on October 28, 2013 in Query Logics, SQL

 

SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 3 of 31

 

SQL SERVER – 2008 – Introduction to Table-Valued Parameters with Example

 
Leave a comment

Posted by on July 6, 2013 in SQL

 

Swap Value Between Two Row Of Columns In MS-SQL

Swap Value Between Two Row Of Columns In MS-SQL

Following Code Will Help you to Swap Value Between Two Row Of Columns In MS-SQL

 begin tran

declare @sum int

select @sum = sum(DisplaySeq)
from CustomCatalogForm
where CustomCatalogFormId in (1,2)

update CustomCatalogForm
set DisplaySeq = @sum - DisplaySeq
where CustomCatalogFormId in (1,2)

commit tran

I hope this helps, good luck!

 

Tags: , , ,

Add CSS File At Run Time in ASP.NET using VB.NET

To Add CSS File At Run Time

Following Code Will Help you to Add Css At Run time in Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

Dim myHtmlLink1 As New HtmlLink
myHtmlLink1.Href = "../Css/Stylesheet.css"
myHtmlLink1.Attributes.Add("rel", "stylesheet")
myHtmlLink1.Attributes.Add("type", "text/css")
Page.Header.Controls.Add(myHtmlLink1)

End Sub

 
1 Comment

Posted by on June 12, 2013 in ASP.NET

 

Tags:

Update data from one existing row to another existing row

Update data from one existing row to another existing row

review the following example

CREATE TABLE #abc(
id int,
Name varchar(50),
SurName varchar(50)
)
Insert into #abc values (1,'Anil','Shah')
Insert into #abc values (2,'Kuldeep','singh')
Insert into #abc values (3,'Waheed','panjri')
Insert into #abc values (4,'Sumit','sutar')

Select * From #abc

Update #abc Set Name= c.Name,
SurName=c.SurName From
(Select Name,SurName From #abc Where id=1)c
Where id=4

I hope this helps, good luck!

 
Leave a comment

Posted by on June 12, 2013 in SQL

 

Tags: , ,