owl

Tuesday, September 15, 2009

Query To get all the tables in Database

SELECT *
FROM sys.objects
WHERE type = 'u'

-------------------------------
Where 'u' stands for USER_TABLE
Where 'P' stands for SQL_STORED_PROCEDURE
Where 'TR' stands for SQL_TRIGGER



-------------------------------

To show all the store procedures in a database

SELECT name
FROM sys.objects
WHERE type = 'P'


Following script will provide name of all the stored procedure which were created in last 7 days, they may or may not be modified after that.
-------------------------------------------------------------------------------------
SELECT *
FROM sys.objects
WHERE type = 'P'
AND DATEDIFF(D,create_date,GETDATE()) < 7

Specifiying connection string in Registry

go to start-->Run-->regedit Registory editor opens..

right click on Software and to add new key by name Myproject..(right click software new->key)

then go to Myproject and rightclick to add new key by name proj01(same as above)

after creating the proj01 key ..right click on the right pane to add a string value..to do that
right click on right pane new->string value

here the connection string can be specified in the string value in the "data" column and name as "ConnKey"

" server=192.110.210.34;database=MyDatabase;uid=user01;pwd=user01; "

==============================================================================================
go to web.config
in <appSettings> section write the folowing code

<appSettings>

<add key="RegistryPath" value="SOFTWARE\MyProject\Proj01"/>

</appSettings>


to get the connection string from the registry path
=====================================================
public static string GetConnectionString()
{
string ConnString = string.Empty;
RegistryKey regPath = Registry.LocalMachine.OpenSubKey(ConfigurationManager.AppSettings["RegistryPath"].ToString(), false);
try
{
if (regPath != null)
{
ConnString = regPath.GetValue("ConnKey").ToString();
}
else
{
throw new Exception("Error in establishing Connection with the DataBase");
}
}
catch (Exception e)
{
throw e;
}
return ConnString;
}

Thursday, September 10, 2009

Concatinating Multiple column value into a single column

Concatinating Multiple column value into a single column

SELECT a.ID 'PropertyID', a.Heading,RateSummary AS Description,c.propertyphotopath,pm.Photos,
pm.Visitors,pm.Inquiries,pm.PublishedDate,a.ExpiryDate
,Case pm.Photos when 0 then '' else 'Currently with'+' '+convert(varchar(50),pm.Photos)+' '+'Photos' End+','
+Case pm.Inquiries when 0 then '' else convert(varchar(50),pm.Inquiries)+' '+'Inquiries Since'+' '+convert(varchar(50),FirstEnquiryDate,106)+',' End
+Case pm.Visitors when 0 then '' else convert(varchar(50),pm.Visitors)+' '+'Visitors Since'+' '+Convert(varchar(50),FirstVisitedDate,106)+'
,' end
+Case DATEDIFF(day,,a.ExpiryDate) when 0 then '' else 'Expires in '+ ' '+convert(varchar(50),DATEDIFF(day, a.createdDate,a.ExpiryDate))+' '+'Days on'+' '+convert(varchar(50),a.ExpiryDate,106) end
+case isnull(pm.PublishedDate,0) when 0 then '' else ' '+'First Published on'+convert(varchar(50),pm.PublishedDate,106) end
FROM PropertyInfo a
INNER JOIN RateDetail b ON a.ID = b.PropertyInfoID
LEFT OUTER JOIN photogallery c ON a.ID = c.PropertyInfoID
Inner join propertymetrics pm on a.ID=pm.PropertyInfoID
WHERE c.ISthumbnail = 'TRUE';

To Bind A value from database to button and using that value to redirect in code behind file

Using OnCommand in Button

.aspx page
--------------
<asp:ImageButton ID="img01" runat="server" ImageUrl="~/Images/edit_j_btn.jpg" OnCommand="onEdit_Click" CommandArgument='<%#Eval("UserId") %>' />

code behind
--------------
public void onEdit_Click(object sender,System.Web.UI.WebControls.CommandEventArgs e)
{
int userid= Convert.ToInt32(e.CommandArgument);
Response.Redirect("Home.aspx?_UserId=" + userid);
}

Monday, August 31, 2009

Friday, August 28, 2009

Javascript click() does not cause a Response.Redirect in asp.net

JavaScript click() does not cause a Response.Redirect in asp.net

when Page has 2 text box and button pair(ie)one for search and the other for lo gin.

The main problem that's encountered here is when the user enters the user name and password and presses the enter key the lo gin button click event is not called as the search button on top of the page has the default focus.

In HTML there is an option to set default focus and default button.
Defaultbutton as the search button(btnsearch)
and DefaultFocus as search textbox(txtsearch)

in some scenario this may not help.so we go for key press event to capture the "enter key" press
TextMode="Password" TabIndex="1" onkeypress="KeyCheck();" >



//This function will be invoked when the enter key is pressed after keying in user name followed by the password
//if the key pressed is an Enter Key the we are calling the server side button click event..this can be achieved with
//the help of JavaScript "click()" method..

//Click() method calls the button click event in the server side and after performing the operation the control returns back

//to the JavaScript key press event call..in case if we like to redirect to an other page on this click event, we will have

//to cancel the click event in order to redirect.to achieve that " window.event.return Value = false;" this method has to be called

function KeyCheck()
{
if (event.keyCode ==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}

function KeysCheck(e)
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
alert("ascx");
document.getElementById('ctl00_ContentPlaceHolder1_BasicSearch1_btnSearch').click();
window.event.returnValue = false;
}
}
}


Following Code will check the type of browser and execute accordingly.

function KeyCheck(e)
{
var browserName="";
var ua=navigator.userAgent.toLowerCase();
if ( ua.indexOf( "firefox" ) != -1 )
{
browserName = "firefox";
}
else if ( ua.indexOf( "msie" ) != -1 )
{
browserName = "msie";
}

if(browserName=="firefox")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
e.preventDefault();
}
}
else if(browserName=="msie")
{
var key=e.keyCode? e.keyCode : e.charCode
if (key==13)
{
document.getElementById('ctl00_ContentPlaceHolder1_btnLogin').click();
window.event.returnValue = false;
}
}
}