Jan 6, 2012
Dec 15, 2011
How to restore database when database was suspect
Kalpesh Satasiya
5:12 PM
ahmedabad, cursor in sql server, software developer, software development, sql server database suspect, suspect database, web developer, web development
3 comments
ALTER DATABASE DataBaseName SET EMERGENCY
DBCC checkdb(DataBaseName)
ALTER DATABASE DataBaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (DataBaseName, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DataBaseName SET MULTI_USER
Nov 30, 2011
Create Dynamic Excel file using Asp.Net
{
// make sure nothing is in response stream
response.Clear();
response.Charset = "";
// set MIME type to be Excel file.
response.ContentType = "application/ms-excel";
// add a header to response to force download (specifying filename)
response.AddHeader("Content-Disposition", "attachment; filename=\"MyFile.xls\"");
for (int i = 0; i < 10; i++)
{
// Send the data. Tab delimited, with newlines.
response.Write("Col1 \t Col2 \t Col3 \t Col4 \n");
}
// Close response stream.
response.End();
}
Nov 18, 2011
Parent Child Relationship on self table in sqlserver
Kalpesh Satasiya
3:41 PM
ahmedabad, parent child relation ship in sql server, self relation in sql server, software developer, software development, web developer
2 comments
(
EmpID int PRIMARY KEY,
EmpName varchar(30),
MgrID int FOREIGN KEY REFERENCES Emp(EmpID)
)
GO
Insert few record into table
INSERT dbo.Emp SELECT 1, 'President', NULL
INSERT dbo.Emp SELECT 2, 'Vice President', 1
INSERT dbo.Emp SELECT 3, 'CEO', 2
INSERT dbo.Emp SELECT 4, 'CTO', 2
INSERT dbo.Emp SELECT 5, 'Group Project Manager', 4
INSERT dbo.Emp SELECT 6, 'Project Manager 1', 5
INSERT dbo.Emp SELECT 7, 'Project Manager 2', 5
INSERT dbo.Emp SELECT 8, 'Team Leader 1', 6
INSERT dbo.Emp SELECT 9, 'Software Engineer 1', 8
INSERT dbo.Emp SELECT 10, 'Software Engineer 2', 8
INSERT dbo.Emp SELECT 11, 'Test Lead 1', 6
INSERT dbo.Emp SELECT 12, 'Tester 1', 11
INSERT dbo.Emp SELECT 13, 'Tester 2', 11
INSERT dbo.Emp SELECT 14, 'Team Leader 2', 7
INSERT dbo.Emp SELECT 15, 'Software Engineer 3', 14
INSERT dbo.Emp SELECT 16, 'Software Engineer 4', 14
INSERT dbo.Emp SELECT 17, 'Test Lead 2', 7
INSERT dbo.Emp SELECT 18, 'Tester 3', 17
INSERT dbo.Emp SELECT 19, 'Tester 4', 17
INSERT dbo.Emp SELECT 20, 'Tester 5', 17
GO
Create sql function
create FUNCTION [dbo].[ShowHierarchy]
(
@Root bigint
)
RETURNS
@menutable TABLE(EmpName varchar(max),MgrID int,EmpID int)
AS
BEGIN
DECLARE @EmpID int, @EmpName varchar(30),@MgrID int, @rootid bigint
set @rootid =@Root
SELECT @EmpID=EmpID,@EmpName=EmpName,@MgrID=MgrID FROM dbo.Emp WHERE EmpID = @Root
-- SET @EmpName = (SELECT EmpName FROM dbo.Emp WHERE EmpID = @Root)
if(@EmpName is not null)
begin
insert into @menutable select REPLICATE(' ', @@NESTLEVEL * 4) + @EmpName,@MgrID,@EmpID
end
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @Root)
WHILE @EmpID IS NOT NULL
BEGIN
insert into @menutable select * from dbo.ShowHierarchy(@EmpID)
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @rootid AND EmpID > @EmpID)
END
return
END
//call this function from where you want
Select * from dbo.ShowHierarchy(0)
Nov 15, 2011
Nov 11, 2011
Sep 22, 2011
How to call server side function using JQuery in Asp.net
Kalpesh Satasiya
3:04 PM
ahmedabad, asp.net, Call server side function using Jquery, jquery, software developer, software development, web developer, web development
No comments
-------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Call server side method using Jquery</title>
<!-- Add the jQuery Reference Library-->
<script src="Script/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#btnok').click(function() {
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<span id="status"></span>
</div>
</form>
</body>
</html>
Code Behide file code (Default.aspx.cs)
-----------------------------------------
Sep 3, 2011
Disable Validation Control From JavaScript.
Aug 24, 2011
Sometimes Page load event not firing in asp.net
Kalpesh Satasiya
4:22 PM
ahmedabad, caching page, event not work, india, page load, page load event, software developer, software development, web developer, web development
No comments
The reason for the page executing doesn't affect the page cycle, the Load event always fires when the page is executed.
So, if the Page_Load doesn't run sometimes, it's because the page is cached and doesn't execute on the server. The page can be cached in the browser, in a router somewhere along the way, or on the server using server side page caching.
If you haven't enabled server side page caching for the page, it's cached in the browser or in the network. You can use cache settings to try to elliminate this:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Aug 4, 2011
Excel Data Reader - Read Excel files in .NET (Convert Excel data to DataTable using Asp.Net)
Kalpesh Satasiya
5:56 PM
ahmedabad, convert excel to datatable, import excel file, india, software developer, software development, web developer, web development
No comments
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader =ExcelReaderFactory.CreateBinaryReader(stream);
//... //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
//... //4. DataSet - Create column names from first row
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
//5. Data Reader methods
while (excelReader.Read()) { //excelReader.GetInt32(0); }
//6. Free resources (IExcelDataReader is IDisposable) excelReader.Close();
I hope help to you.
Jul 12, 2011
Get Physical Path using Asp.Net
Kalpesh Satasiya
5:35 PM
ahmedabad, asp.net, get physical path, india, physical path, software developer, software development, web designing
No comments
Jul 7, 2011
India Currency Format in .Rdcl report and Write custom function in .Rdcl Report.
Kalpesh Satasiya
6:06 PM
.Rdcl report, ahmedabad, custom function in .rdlc report, india, India Currency format, software developer, software development
No comments
Jul 6, 2011
Declare Nested Cursor in Sql Server
Kalpesh Satasiya
5:41 PM
ahmedabad, cursor in sql server, declare nested cursor, india, nested cursor, software developer, software development
1 comment
--Declare outer cursor
fetch next from @inner_cursor into @cartid, @qty while(@@FETCH_STATUS=0)
Jun 21, 2011
Jun 17, 2011
Use .VB and .CS class file in one website using asp.net
Kalpesh Satasiya
2:06 PM
.CS class, .VB and .CS class file use in one project, .VB class, ahmedabad, asp.net, india, software developer, software development
No comments
When I was creating my one of the site, I chose to write it in C#. I had a problem with the App_Code folder because I had some code in VB.NET code and some C# code I needed to put in there. I didn't want to rewrite my VB.NET code in the App_Code folder just so I could write the rest of the code for the site in C#.
Luckily, the ASP.NET Team had already thought about just this kind of circumstance. They implemented a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn't have to spend a couple hours converting code from VB.NET to C#!
The below works with ASP.NET 2.0 and later.
Even if you don't use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.
Step 1: Add the following lines to the web.config
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="VB_Code"/>
<add directoryName="CS_Code"/>
codeSubDirectories>
compilation>
system.web>
configuration>
Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:
/App_Code/VB_Code
/App_Code/CS_Code
Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.
Display India Currency format using JavaScript
Kalpesh Satasiya
9:55 AM
ahmedabad, convert currency format, india, India Currency format, JavaScript, software developer, software development
No comments
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
var z = 0;
var len = String(x1).length;
var num = parseInt((len/2)-1);
while (rgx.test(x1))
{
if(z > 0)
{
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
else
{
x1 = x1.replace(rgx, '$1' + ',' + '$2');
rgx = /(\d+)(\d{2})/;
}
z++;
num--;
if(num == 0)
{
break;
}
}
return x1 + x2;
}
Jun 7, 2011
Jun 6, 2011
Reduce Image File Size Using Asp.Net
Kalpesh Satasiya
5:56 PM
ahmedabad, asp.net, dynamic reduce image file size, india, Reduce file size, Reduct image file size, software developer, software development
No comments
imageSave(fluCatImage.FileName, fluCatImage.PostedFile.InputStream, Server.MapPath("~/"), Server.MapPath("../uploadimage/"));
//Implement Function
public void imageSave(string imagename, Stream s, string serverpath, string foldername)
{
if (imagename != string.Empty)
{
System.Drawing.Image image = System.Drawing.Image.FromStream(s);
Bitmap source = new Bitmap(image); //<-- or any other source
Bitmap target = new Bitmap(source.Width, source.Height);
Graphics g = Graphics.FromImage(target);
EncoderParameters e;
g.CompositingQuality = CompositingQuality.HighSpeed; //<-- here
g.InterpolationMode = InterpolationMode.Low;// <-- here
Rectangle recCompression = new Rectangle(0, 0, source.Width, source.Height);
g.DrawImage(source, recCompression);
e = new EncoderParameters(2);
e.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)70);// <-- here 70% quality
e.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW); //<-- here
DateTime MyDate = DateTime.Now;
source.Dispose();
string imgname = DateTime.UtcNow.ToString().Replace(" ", "").Replace("AM", "").Replace("PM", "").Replace("/", "").Replace("-", "").Replace(":", "");
String MyString = imgname + ".jpg";
target.Save(foldername + MyString, GetEncoderInfo("image/jpeg"), e);
// MemoryStream ms = new MemoryStream();
// target.Save(ms, GetEncoderInfo("image/jpeg"),e);
// ms.WriteTo(ms);
g.Dispose();
target.Dispose();
}
}
public static ImageCodecInfo GetEncoderInfo(string sMime)
{
ImageCodecInfo[] objEncoders;
objEncoders = ImageCodecInfo.GetImageEncoders();
for (int iLoop = 0; iLoop <= (objEncoders.Length - 1); iLoop++)
{
if (objEncoders[iLoop].MimeType == sMime)
return objEncoders[iLoop];
}
return null;
}