DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, YourTable has 25 rows with 25 as last identity. If we want next record to have identity as 35 we need to run following T SQL script in Query Analyzer.
DBCC CHECKIDENT (yourtable, reseed, 34)
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.
Friday, May 28, 2010
Image Uploader
private void UploadLogo(string LogoFileName)
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
try
{
if (Directory.Exists(Server.MapPath("..\\AssociateLogos")))
{
//string path = "\\images\\";
string path = "..\\AssociateLogos\\";
int a = LogoFileName.LastIndexOf("/");
string fileName = LogoFileName.Substring(a+1);
string Serverpath = Server.MapPath(path);
FileUpload1.SaveAs(Serverpath +
fileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "
" +
FileUpload1.PostedFile.ContentLength + " kb
" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
else
{
Directory.CreateDirectory(Server.MapPath("..\\AssociateLogos"));
string path = "..\\AssociateLogos\\";
string Serverpath = Server.MapPath(path);
FileUpload1.SaveAs(Serverpath +
LogoFileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "
" +
FileUpload1.PostedFile.ContentLength + " kb
" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "You have not specified a file.";
}
}
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
try
{
if (Directory.Exists(Server.MapPath("..\\AssociateLogos")))
{
//string path = "\\images\\";
string path = "..\\AssociateLogos\\";
int a = LogoFileName.LastIndexOf("/");
string fileName = LogoFileName.Substring(a+1);
string Serverpath = Server.MapPath(path);
FileUpload1.SaveAs(Serverpath +
fileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "
" +
FileUpload1.PostedFile.ContentLength + " kb
" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
else
{
Directory.CreateDirectory(Server.MapPath("..\\AssociateLogos"));
string path = "..\\AssociateLogos\\";
string Serverpath = Server.MapPath(path);
FileUpload1.SaveAs(Serverpath +
LogoFileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "
" +
FileUpload1.PostedFile.ContentLength + " kb
" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "You have not specified a file.";
}
}
Thursday, May 27, 2010
Splitting CSV
#region "Splitting CSV"
private int[] commaStrToArray(string strIntComma)
{ string [] strArray; strArray = strIntComma.Split(new char[] {','}); int [] intArray = new int [strArray.Length]; for (int i = 0; i < strArray.Length; i++) intArray[i] = int.Parse(strArray[i]); return intArray; }
#endregion
private int[] commaStrToArray(string strIntComma)
{ string [] strArray; strArray = strIntComma.Split(new char[] {','}); int [] intArray = new int [strArray.Length]; for (int i = 0; i < strArray.Length; i++) intArray[i] = int.Parse(strArray[i]); return intArray; }
#endregion
Monday, May 24, 2010
Temp Table Creation Insertion and Display
declare @table table(id int identity(1,1),userid int, Fullname varchar(250),DepartmentName)
insert into @table(userid,Fullname,DepartmentName)
select distinct a.userid , fullname ,deptname from table1
select * from @table
insert into @table(userid,Fullname,DepartmentName)
select distinct a.userid , fullname ,deptname from table1
select * from @table
Open Child Window
function OpenWinForUpdation(code)
{
//window.open(url,'meeting Mangement','toolbar=0,width=900,height=600');
window.open('Abc.aspx?fc='+code,'Roza','toolbar=0,width=1200,height=800,scrollbars=yes');
//window.location.href = url;
}
{
//window.open(url,'meeting Mangement','toolbar=0,width=900,height=600');
window.open('Abc.aspx?fc='+code,'Roza','toolbar=0,width=1200,height=800,scrollbars=yes');
//window.location.href = url;
}
JQuery Accordian
function openDiv()
{
//$('#openDiv').click(function() {
// alert( $('#divContent'));
$('#ShowHide').slideToggle('slow');
// });
}
{
//$('#openDiv').click(function() {
// alert( $('#divContent'));
$('#ShowHide').slideToggle('slow');
// });
}
Child Window Closed
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Cl", "alert('Keyword Added Successfully'); self.close();", true);
Child Window Closed and Parent Refresh
Just Write this on button submit event
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Cl", "alert('Keyword Added Successfully');opener.location.href = opener.location.href;this.close();", true);
ALternate
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Cl", "parent.hs.close();parent.location.href = parent.location.href;", true);
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Cl", "alert('Keyword Added Successfully');opener.location.href = opener.location.href;this.close();", true);
ALternate
ScriptManager.RegisterClientScriptBlock(this, GetType(), "Cl", "parent.hs.close();parent.location.href = parent.location.href;", true);
Find any keyword used in any stored procedure
select distinct name from sysobjects sc
inner join syscomments sc2
on sc.id = sc2.id
where
sc2.text like '%between%'
order by name desc
inner join syscomments sc2
on sc.id = sc2.id
where
sc2.text like '%between%'
order by name desc
Date Btween Date Range check
select top 500 convert(datetime,LastUpdated_Date,101),* from contactDetails
where convert(datetime,LastUpdated_Date,101) between convert(datetime,'Apr 01, 2009',101) and convert(datetime,'May 31, 2010',101)
where convert(datetime,LastUpdated_Date,101) between convert(datetime,'Apr 01, 2009',101) and convert(datetime,'May 31, 2010',101)
DropDown Lsit Filter Search Stored Procedure
CREATE PROCEDURE [dbo].[SR_SelectProjectsDetailsForSpecificStatusWithSpecificUser]
@Portal_User_ID INT,
@Project_status_code INT,
@Category_Code int
AS
BEGIN
SET NOCOUNT ON
IF(ISNULL(@Project_status_code,0) > 0)
BEGIN
SELECT Project.Project_Code, Project.Project_Name, Project.Project_type_Code, Project.Project_Type_Details, Project.Project_status_code,
Project.Project_DeadLine, ProjectCategory.Category_Name, ProjectStatus.Project_Status_Name, ProjectType.Project_Type_Name,
ProjectResource.Portal_User_ID, ProjectResource.Role_Code, ProjectResource.Project_code AS Expr1
FROM Project (NOLOCK)
INNER JOIN ProjectStatus (NOLOCK)
ON Project.Project_status_code = ProjectStatus.Project_Status_code
INNER JOIN ProjectCategory (NOLOCK)
ON Project.Category_Code = ProjectCategory.Category_Code
INNER JOIN ProjectType (NOLOCK)
ON Project.Project_type_Code = ProjectType.Project_Type_Code
INNER JOIN ProjectResource (NOLOCK)
ON Project.Project_Code = ProjectResource.Project_code
WHERE Project.Project_status_code=@Project_status_code and ProjectResource.Portal_User_ID=@Portal_User_ID and Project.Category_Code=@Category_Code
ORDER BY Project.Project_Code DESC
END
ELSE
BEGIN
SELECT Project.Project_Code, Project.Project_Name, Project.Project_type_Code, Project.Project_Type_Details, Project.Project_status_code,
Project.Project_DeadLine, ProjectCategory.Category_Name, ProjectStatus.Project_Status_Name, ProjectType.Project_Type_Name,
ProjectResource.Portal_User_ID, ProjectResource.Role_Code, ProjectResource.Project_code AS Expr1
FROM Project (NOLOCK)
INNER JOIN ProjectStatus (NOLOCK)
ON Project.Project_status_code = ProjectStatus.Project_Status_code
INNER JOIN ProjectCategory (NOLOCK)
ON Project.Category_Code = ProjectCategory.Category_Code
INNER JOIN ProjectType (NOLOCK)
ON Project.Project_type_Code = ProjectType.Project_Type_Code
INNER JOIN ProjectResource (NOLOCK)
ON Project.Project_Code = ProjectResource.Project_code
WHERE ProjectResource.Portal_User_ID=@Portal_User_ID and Project.Category_Code=@Category_Code
ORDER BY Project.Project_Code DESC
END
SET NOCOUNT OFF
END
@Portal_User_ID INT,
@Project_status_code INT,
@Category_Code int
AS
BEGIN
SET NOCOUNT ON
IF(ISNULL(@Project_status_code,0) > 0)
BEGIN
SELECT Project.Project_Code, Project.Project_Name, Project.Project_type_Code, Project.Project_Type_Details, Project.Project_status_code,
Project.Project_DeadLine, ProjectCategory.Category_Name, ProjectStatus.Project_Status_Name, ProjectType.Project_Type_Name,
ProjectResource.Portal_User_ID, ProjectResource.Role_Code, ProjectResource.Project_code AS Expr1
FROM Project (NOLOCK)
INNER JOIN ProjectStatus (NOLOCK)
ON Project.Project_status_code = ProjectStatus.Project_Status_code
INNER JOIN ProjectCategory (NOLOCK)
ON Project.Category_Code = ProjectCategory.Category_Code
INNER JOIN ProjectType (NOLOCK)
ON Project.Project_type_Code = ProjectType.Project_Type_Code
INNER JOIN ProjectResource (NOLOCK)
ON Project.Project_Code = ProjectResource.Project_code
WHERE Project.Project_status_code=@Project_status_code and ProjectResource.Portal_User_ID=@Portal_User_ID and Project.Category_Code=@Category_Code
ORDER BY Project.Project_Code DESC
END
ELSE
BEGIN
SELECT Project.Project_Code, Project.Project_Name, Project.Project_type_Code, Project.Project_Type_Details, Project.Project_status_code,
Project.Project_DeadLine, ProjectCategory.Category_Name, ProjectStatus.Project_Status_Name, ProjectType.Project_Type_Name,
ProjectResource.Portal_User_ID, ProjectResource.Role_Code, ProjectResource.Project_code AS Expr1
FROM Project (NOLOCK)
INNER JOIN ProjectStatus (NOLOCK)
ON Project.Project_status_code = ProjectStatus.Project_Status_code
INNER JOIN ProjectCategory (NOLOCK)
ON Project.Category_Code = ProjectCategory.Category_Code
INNER JOIN ProjectType (NOLOCK)
ON Project.Project_type_Code = ProjectType.Project_Type_Code
INNER JOIN ProjectResource (NOLOCK)
ON Project.Project_Code = ProjectResource.Project_code
WHERE ProjectResource.Portal_User_ID=@Portal_User_ID and Project.Category_Code=@Category_Code
ORDER BY Project.Project_Code DESC
END
SET NOCOUNT OFF
END
Export Crystal Reports to PDF file
Reports are used by business for various management purposes. Crystal reports is very versatile and easy to use reporting tool that is bundled with the Microsoft Visual Studio .Net. There have been many enhancements in the latest version of crystal reports which make it simpler for developers to export reports directly to the HTTP response object.
Read More http://www.beansoftware.com/asp.net-tutorials/export-crystal-reports-to-pdf.aspx
Read More http://www.beansoftware.com/asp.net-tutorials/export-crystal-reports-to-pdf.aspx
Subscribe to:
Posts (Atom)