Saturday, March 10, 2012

change the same column names in all tables using cursors

Create procedure [dbo].[sp_RenameColumName]
@OldColumnName nvarchar(200),
@NewColumnName nvarchar(200)
as
Declare @column_name nvarchar(200)
DECLARE db_cursor CURSOR FOR
SELECT
(t.name+'.'+c.name) AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%'+@OldColumnName+'%'
Begin
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @column_name
WHILE @@FETCH_STATUS = 0
BEGIN
exec sp_rename @column_name,@NewColumnName, 'COLUMN'
FETCH NEXT FROM db_cursor into @column_name
END
CLOSE db_cursor
DEALLOCATE db_cursor
End

Wednesday, March 7, 2012

Monday, February 27, 2012

Display Image in Image Control while Uploading Image Using FileUpload Control

Source File Code:
<script type="text/javascript">
function UploadImage()
{
document.getElementById('<%=BtnTemp.ClientID %>').click();
}
</script>
<asp:Image ID="Image1" runat="server" Height="97px" Width="130px" />
<asp:FileUpload ID="FileUpload1" OnChange="return UploadImage();" runat="server"
/> <div id="hide" style="display:none">
<asp:Button ID="BtnTemp" runat="server" OnClick="BtnTemp_Click" />
</div>
.Cs file Code:
protected void BtnTemp_Click(object sender, EventArgs e)
{
string FileName = FileUpload1.FileName;
string GudID = Guid.NewGuid().ToString();
string fullname = GudID +"_"+ FileName;
FileUpload1.SaveAs(Server.MapPath("~/Images/" + fullname));
Image1.ImageUrl = "~/Images/" + fullname;
}

Wednesday, February 22, 2012

Generate Unique Identity Value Using Datepart in SQLServer :

create procedure SP_Insert_Customer
as
begin
declare @CustomerID nvarchar(50)
set @CustomerID=CONVERT(nvarchar(10),DATEPART(MM,getdate()))+ CONVERT(nvarchar(10),DATEPART(YYYY,getdate()))
+ CONVERT(nvarchar(10),(select COUNT(*) from dbo.Users)+ 1)
print(@ID);
end
O/P:220124 i.e Month Year Number of rows in the table

Monday, February 20, 2012

Get Identity column value after Inserting the record into Database Table

Create procedure [dbo].[SP_Insert_Employee]
@EmpId int output,
@Name nvarchar(50),
@Address nvarchar(50),
as
begin
insert into dbo.Employee(Name,Address) values(@Name,@Address )
set @EmpId=SCOPE_IDENTITY();
end

Thursday, February 16, 2012

Hide part webpage when the webpage was printing

PrintForm = function (strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=480,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML = strOldOne;
}
Here’s the webpage, the printable area must be inside a div:
<div id="divPrint">
SAMPLE CONTENT
</div>

<input id="btnPrintBottom" type="button" value="Print" onclick="PrintForm('divPrint')" />

Print button hiding:
document.getElementById('Button').style.visibility = "hidden";
Display TextBox data into Label :
var b = document.getElementById('<%=TextBox1.ClientID %>').value;
document.getElementById('lb').style.display = "block";
var c = document.getElementById('<%=lblName.ClientID %>').innerText= b.toString();

Wednesday, February 15, 2012

Copy data from one Textbox to another Textbox while User entering data

on the keypress event of the textbox write the following code
document.getElementByID('<%=TextBox2.ClientID%>').Text = document.getElementByID('<%=TextBox1.ClientID%>').Text
<asp:textbox id="TextBox" runat=server onkeypress="document.getElementByID('<%=TextBox2.ClientID%>').Text =
document.getElementByID('<%=TextBox1.ClientID%>').Text"> </asp:textbox>
onblur event of the textbox write the following code
//javaScript
function fnFromToTextBox(firstTxtBox,secondTxtBox)
{
secondTxtBox.value=firstTxtBox.value;
}
//on Code behind
txtCompany.Attributes.Add("onblur", "fnFromToTextBox(txtCompany,txtBilling)");
Using Keyup:
<asp:TextBox id="TextBox1" onkeyup="document.getElementById("TextBox2").value = this.value;"></asp:TextBox>