this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...
Tuesday, December 29, 2009
SQL Script to Find Week Days of a Year and J-Query
Wednesday, December 23, 2009
Image Gallery using j-query
Tuesday, December 22, 2009
True paging using SQL script
data per page.
Although the data is distributed among different pages however it is fetched at a longer period of time
An efficient way is to fetch data per page.
Following example helps you search news and display results accordingly by stored procedure.
CREATE PROCEDURE [dbo].[News_Search]
@SearchText nvarchar(100) --Search text,what we want ot search in news.
,@PageNo int ----Page number
,@PageSize int-----Page size
,@TotalRecords int output--Total how many records are there in search result
AS
BEGIN
SET NOCOUNT ON;
DECLARE @StartFrom int
SET @StartFrom = @PageSize * (@PageNo - 1);
SET @TotalRecords=(SELECT ISNULL(COUNT(*),0)FROM ViwNews
WHERE ViwNews.NewsIsDisable <> 0 and
@SearchText Is Null OR ViwNews.NewsTitle Like @SearchText);
SELECT searchtable.*
FROM
(SELECT
ROW_NUMBER() OVER (ORDER BY ViwNews.NewsTitle)AS [RecNo]
,ViwNews.*
FROM ViwNews
WHERE ViwNews.NewsIsDisable <> 0 and
@SearchText Is Null OR ViwNews.NewsTitle Like @SearchText
) AS searchtable
WHERE searchtable.RecNo > @StartFrom And searchtable.RecNo <=(@StartFrom+@PageSize);
END
In above query we have 4 parameters.
1) @SearchText used to pass for the search criteria.
2) @PageNo used to fetch which page number we want to fetch from the result.
3) @PageSize used to determine page size
4) @TotalRecords used to create number of pages
We can determine number of pages by dividing total records with page size.
In query we have used ROW_NUMBER() function which gives Record number obtained in the result sequentially.
Javascript to allow only numeric in text box
hi , many times we come to situation when in our website we just want to allow numeric value in text box.
This can be done by the client side java script.
Below is the script you need to insert
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode <> 57))
return false;
return true;
}
and here is how to attach this function to your text box either its html or asp.net text box.
onkeypress="return isNumberKey(event)"
Monday, December 7, 2009
How to send email Asynchronously
When Our smtp Serve does not respond to immediately at that time it takes time to send email. So it happens that our application does not respond to user and user shut down our application. In this case its wise that we should send email Asynchronously and when email send successfully we just give notification it send successfully or not sent what so ever. This all things are available in the .net framework 2.0.
//Send email
SmtpClient sc = new SmtpClient(“smtp.abc.com”);
sc.Send(mm);
//Wire up event of SendCompleted
sc.SendCompleted += new SendCompletedEventHandler(sc_SendCompleted);
sc.SendAsync(mm,null);
void sc_SendCompleted(object sender, AsyncCompletedEventArgs e)
{ if(e.Cancelled)
{
MessageBox.Show(“Message sending is Cancelled”);
}
else if(e.Error != null)
{
MessageBox.Show(“Error to Send Email Error is:” + e.Error.ToString() );
}
else
{
MessageBox.Show(“Message sent Successfully”);
}
}