Search

Tuesday, March 2, 2010

To dynamically change the text at runtime in Crystal Report

To dynamically change the text at run time you will need to change the value of the TextObject programmatically. All report objects are accessed through the ReportDocument.ReportDefinition.ReportObjects collection.

1. Right-click Form1.cs in the Solution Explorer and select View Code
2. In the Form1 class, add the following code:

ReportDocument rd = new ReportDocument();

rd.Load(@"C:\\CrystalReport1.rpt");

((CrystalDecisions.CrystalReports.Engine.TextObject)rd.ReportDefinition.ReportObjects["text1"]).Text = "Italy Wins!!";

crystalReportViewer1.ReportSource = rd;

Sunday, January 31, 2010

Char Index Replace LastWord with New Word in sql

select email, SUBSTRING(email, CHARINDEX('@',email)+1,30) from details where len(email) > 0

--Replace all email domain name with new domain name

--ex:-@abc.com replace by @def.com

UPDATE details

SET Email=REPLACE(Email,SUBSTRING(email, CHARINDEX('@',email)+1,30),'def.com') where len(email) > 0

To Replace All Accurence in all Database (Find Replace From All Database)

--To replace all occurences of 'Accenture' with 'Yahoo':
EXEC SearchAndReplace 'Accenture', 'Yahoo'
GO



CREATE PROC SearchAndReplace
(
@SearchStr nvarchar(100),
@ReplaceStr nvarchar(100)
)
AS
BEGIN


SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110), @SQL nvarchar(4000), @RCTR int
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
SET @RCTR = 0

WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)

WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)

IF @ColumnName IS NOT NULL
BEGIN
SET @SQL= 'UPDATE ' + @TableName +
' SET ' + @ColumnName
+ ' = REPLACE(' + @ColumnName + ', '
+ QUOTENAME(@SearchStr, '''') + ', ' + QUOTENAME(@ReplaceStr, '''') +
') WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
EXEC (@SQL)
SET @RCTR = @RCTR + @@ROWCOUNT
END
END
END

SELECT 'Replaced ' + CAST(@RCTR AS varchar) + ' occurence(s)' AS 'Outcome'
END

Search text from all stored Procedure in One Database

The following stored procedure will list all stored procedure names whose text contains the parameter search string.


CREATE PROCEDURE Find_Text_In_SP
@StringToSearch varchar(100)
AS
SET @StringToSearch = '%' +@StringToSearch + '%'
SELECT Distinct SO.Name
FROM sysobjects SO (NOLOCK)
INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
AND SO.Type = 'P'
AND SC.Text LIKE @stringtosearch
ORDER BY SO.Name
GO

--exec Find_Text_In_SP 'vWgetuser'
--find view name from all stored procedure in database

Friday, January 22, 2010

how to get the value of a javascript pop up confirmation box in the middle of some code. - ASP.NET Forums

how to get the value of a javascript pop up confirmation box in the middle of some code.


Untitled Page






Input "abc" in the TextBox is valid




Style="position: static; display: none" Text="Button" />





****************//code behind file
protected void Button2_Click(object sender, EventArgs e)
{
Response.Write("Process OK");
}

protected void Button1_Click(object sender, EventArgs e)
{
if (!TextBox1.Text.Equals("abc"))
{
String csname = "PopupScript";
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "confirmProcess()";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
}
else
{
Response.Write("Process OK");
}
}

Tuesday, September 1, 2009

SQL ERROR when use a Webpart Page

Error:-"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

Answer:-
if aspnetdb setup next you should configure web.config to use web parts here is the code:





<system.web>


<
webParts>

<personalization
defaultProvider="AspNetSqlPersonalizationProvider">


<
providers>

<remove
name="AspNetSqlPersonalizationProvider"/>


<add
name="AspNetSqlPersonalizationProvider"



type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"



connectionStringName="BIMembership"


applicationName="/"/>

</providers>


</
personalization>

</webParts>




Tuesday, July 28, 2009

Backup of All Databasea

--path of backup MSSQL\Backup\Production\My_DB\My_DB_200903251116.bak
--epp2admin is creates a backup in the folder under 'Production' and then creates a ---folder for the database name; then dates the files
DECLARE @MailSubject varchar(1000)
DECLARE @AlertMessage varchar(1000)
DECLARE @MailProfile varchar(1000)
DECLARE @HTMLCode VARCHAR(MAX)
DECLARE @CmdString VarChar(1000)
DECLARE @Path varchar(200)
DECLARE @DB sysname
DECLARE @FullPath varchar(400)

SET @MailProfile = (Select TOP 1 Name from msdb.dbo.SysMail_Profile WHERE Name LIKE '%Email Profile')

BEGIN TRY
CREATE TABLE
#Key (KeyValue Varchar(150), KeyData VarChar(150))
INSERT
#KEY
EXECUTE
master..xp_instance_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer', 'BackupDirectory'
SELECT
@PATH = KeyData + '\ePP2Admin' from #Key
DROP TABLE
#Key

DECLARE CurDB CURSOR FOR

SELECT
DATABASE_NAME = db_name(s_mf.database_id)
FROM
sys.master_files s_mf
WHERE -- ONLINE
s_mf.state = 0 -- Only look at databases to which we have access
and
has_dbaccess(db_name(s_mf.database_id)) = 1 -- Not master, tempdb or model
and
db_name(s_mf.database_id) not in ('Master','tempdb','model')
group by
s_mf.database_id
order by
1

OPEN CurDB
FETCH CurDB into @DB

while @@fetch_status = 0
begin
set @FullPath = @Path + '\' + @db
exec master..xp_create_subdir @FullPath

set @FullPath = @FullPath + '\' + @DB + '_'
+ datename( yyyy , getdate())
+ right('00' + cast(datepart( mm , getdate()) as varchar(2)) , 2 )
+ right('00' + datename( dd , getdate()), 2 )
+ right('00' + datename( hh , getdate()), 2 )
+ right('00' + datename( mi , getdate()), 2 )
+ '.bak'
Backup DATABASE @DB to disk = @FullPath WITH INIT, BLOCKSIZE = 65536
--SET @CMDString = 'BACKUP DATABASE ' + @DB + ' TO DISK = ''' + @FullPath + ''' WITH INIT, STATS = 10'
--EXEC (@CMDString)

fetch curDB into @DB
end
CLOSE CurDB
deallocate curDB
END TRY

BEGIN CATCH
DECLARE @Error_Number INT
DECLARE @Error_Severity INT
DECLARE @Error_State varchar(100)
DECLARE @Error_Message VarChar(1000)

SELECT
@Error_Number = ERROR_NUMBER(),
@Error_Severity = ERROR_SEVERITY(),
@Error_State = ERROR_STATE(),
@Error_Message = ERROR_MESSAGE();
SELECT @MailSubject =
'ALERT: Error ' + CAST(@Error_Number AS Varchar(5)) +
', Severity ' + CAST(@Error_Severity AS Varchar(2)) +
', State ' + CAST(@Error_State AS Varchar(2)) +
', occured on \\' + @@ServerName

SELECT @HTMLCode = @Error_Message

EXEC msdb.dbo.sp_send_dbmail
@profile_name = @MailProfile,
@recipients = 'SQL_Notify@YourCompany.com',
@subject = @MailSubject,
@Body = @HTMLCode
END CATCH

Blog Archive

Contributors