Archive

Posts Tagged ‘FAQs Help and Tutorials’

How to find control with in repeater on button click event

December 10, 2013 Leave a comment

<asp:Repeater ID=”RptInfo” runat=”server”>

<ItemTemplate>

<asp:Panel ID=”pnlReadonly” runat=”server”>

….

</asp:Panel>

</ItemTemplate>

</asp:Repeater>

Code : 

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

Dim pnlReadonly As Panel = DirectCast(RptSoccerInfo.Items(0).FindControl(“pnlReadonly”), Panel)

If (Not pnl Is Nothing) Then
‘ some code
End If

End Sub

Will add some more detail soon .

Cannot drop database because it is currently in use.


This is a very common error when DROP Database is command is executed and the database is not dropped.

The following commands will raise above error:
USE AdventureWorks;
GO
DROP DATABASE AdventureWorks;
GO

Solution:
The following commands will not raise an error and successfully drop the database:

USE Master;
GO
DROP DATABASE AdventureWorks;
GO

If you are still getting the error after you try using
use master
go
drop database (databaseName)
go

Close SQL Server Management Studio completely. Open it again and connect as normal. Now you will be able to drop the database with
use master
go
drop database (databaseName)
go

Hope it helps!

Validate INDIAN PAN Number Using Regular expression

November 29, 2012 Leave a comment

Indian PAN is as follows: AAAAA9999A:
Where First five characters are letters, next 4 numerals, last character letter
One rule there the fourth character is choosen from a list Alphabates as bellows.

C – Company
P – Person
H – HUF(Hindu Undivided Family)
F – Firm
A – Association of Persons (AOP)
T – AOP (Trust)
B – Body of Individuals (BOI)
L – Local Authority
J – Artificial Juridical Person
G – Govt

http://en.wikipedia.org/wiki/Permanent_account_number

Hence I will create a regular expression
as bellow

^[\w]{3}(p|P|c|C|h|H|f|F|a|A|t|T|b|B|l|L|j|J|g|G)[\w][\d]{4}[\w]$

Here I have a textbox and a regular expression validator in my aspx page as bellow.

<asp:TextBox ID="txtPan" runat="server" ></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 

     ControlToValidate="txtPan" runat="server" ErrorMessage="Invalid PAN"      ValidationExpression="^[\w]{3}(p|P|c|C|h|H|f|F|a|A|t|T|b|B|l|L|j|J|g|G)[\w][\d]{4}[\w]$">

</asp:RegularExpressionValidator>

COALESCE with DISTINCT in SQLServer

November 6, 2012 Leave a comment

If you want comma separated values from columns it is so simple. Use COALESCE function provided by SQL Server.

DECLARE @csv varchar(max)
select @csv = COALESCE(@csv + ‘,’ , ‘ ‘) + cast(id  AS VARCHAR) from tablename
print @csv

COALESCE with DISTINCT Values

If you want, DISTINCT values in COALESCE function use inner table like below.

DECLARE @csv varchar(max)
select @csv = COALESCE(@csv + ‘, ‘, ‘ ‘) + cast(id  AS VARCHAR) from
(SELECT DISTINCT id FROM TableName)
print @csv

Hope it helps!