Sharing knowledge in Project, Program, Portfolio Innovation Management (PPIM) and various Technology.
Sunday, April 20, 2008
An easy way to build connection string.
1) Open a New notepad and save it with "udl" extension, suppose "New.udl".
2) Now you will see that it's icon is changed.
3) Open it, you will find Data Link properties dialog box.
4) For SQl Server connection string select Microsoft OLE DB Provider For SQL Server in Provider Tab.
5) Click button "Next" or select Connection Tab
6) Here you can select all connection details and press button
Test Connection. If it is successful close this dialog box.
7) Now open this file using "Notepad", you will find the connection string. Though it is built for OLE DB
type of connection, you can use for SQL Server connection by removing Provider attribute.
NOTE: If you are using SQL Authentication with password, then check the checkbox Allow Saving Password.
This is necessary so that password appears in connection string.
Thursday, April 17, 2008
Paging In Sqlserver 2005
FROM (SELECT ROW_NUMBER() OVER(ORDER BY person) AS
rownum, person, income FROM Salaries) AS Salaries1
WHERE rownum >= 5 AND rownum <= 9
ORDER BY income
Wednesday, April 16, 2008
How to show Modal and Modeless dialog windows in Javascript
When you show a modal dialog the window remains on top of other windows until the user explicitly closes it.
window.showModalDialog("Test.html","dialogWidth:400px; dialogHeight:225px; status:no; center:yes");
When you show a modeless dialog the window remains on top of other windows, but you can still access the other windows.
window.showModalessDialog("Test.html","dialogWidth:400px; dialogHeight:225px; status:no; center:yes");
How do we get ipaddress or hostaddress using c#
HttpContext.Current.Server.MachineName
HttpContext.Current.Request.ServerVariables["local_addr"]
Changing Connection string dynamically using Application_BeginRequest
"Production" and another server name is "Testing". The below code connection string will change dynamically based on server host information.
Example:
<appsettings>
<add key="production" value="http://www.production.com">
<add key="ProductionconnectionString" value="server=localhost;...." >
<add key="testconnectionString" value="server=localhost;...." >
</appsettings>
Public Application_BeginRequest()
{
bool production=false;
if(Request.URL.Host==ConfiqurationManager.Appsettings("production"))
{
Production=true;
}
}
if(Production==true)
{
context.items.add("connectionStrings",ConfiqurationManager.Appsettings("production"))
}
else
{
context.items.add("connectionStrings",ConfiqurationManager.Appsettings("test"))
}
}
Support Multiple Browser Image control
Example:
<asp:image id="cklogo" runat="server" ImageUrl="Images/ck_logo.jpg" PIE4.0:imageurl="Images/small/ck_logo.jpg">
Thursday, April 10, 2008
Cross Joins Using sqlserver
A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. This is an example of a Transact-SQL cross join:
USE pubs
SELECT au_fname, au_lname, pub_name
FROM authors CROSS JOIN publishers
ORDER BY au_lname DESC
The result set contains 184 rows (authors has 23 rows and publishers has 8; 23 multiplied by 8 equals 184).
However, if a WHERE clause is added, the cross join behaves as an inner join. For example, these Transact-SQL queries produce the same result set:
USE pubs
SELECT au_fname, au_lname, pub_name
FROM authors CROSS JOIN publishers
WHERE authors.city = publishers.city
ORDER BY au_lname DESC
-- Or
USE pubs
SELECT au_fname, au_lname, pub_name
FROM authors INNER JOIN publishers
ON authors.city = publishers.city
ORDER BY au_lname DESC
Accessing server event using Ajax
Install system.web.extension and ajax tools
Install ajax.dll in your system all add in reference of the project.
step:2
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
step:3
Write javascript
<script language="javascript" type="text/javascript">
function Getconfirm()
{
var con=confirm("Are sure want to delete this");
var test;
if(con==false)
{
alert(Bala.Getvalue().value);
}
else
{
alert(Bala.Getvalue1().value);
}
}
</script>
step 4:
in c# page
public partial class Bala : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Bala));
//btnsubmit.Attributes.Add("onclick", "Getconfirm();");
}
[Ajax.AjaxMethod()]
public string Getvalue()
{
return "bala";
}
[Ajax.AjaxMethod()]
public string Getvalue1()
{
return "bala1";
}
}
Monday, April 7, 2008
Check if a date is a valid date in Sql Server 2005
Use the ISDATE() function
The ISDATE() function determines whether the variable or the expression contains a valid date. It returns 1(true) if the input expression is a valid date;
otherwise, it returns 0 (false).
For eg:
DECLARE @dt varchar(10)
SET @dt = '02/21/08'
SELECT ISDATE(@dt)-- Returns 1
DECLARE @dt varchar(10)
SET @dt = '13/21/08'
SELECT ISDATE(@dt)-- Returns 0 as 13 is not a valid month
Reset all control values in .NET Web pages.
private void ResetFields()
{
foreach (Control ctrl in this.Controls)
{if (ctrl is TextBox)
{
TextBox tb = (TextBox)ctrl;
if (tb != null)
{ tb.Text = string.Empty;
}
} else
if (ctrl is DropDownList)
{ DropDownList dd = (DropDownList)ctrl;
if (dd != null)
{
dd.SelectedIndex = 0;
}
}
}
How to Show Binary Files in the Browser using ASP.NET and VB.NET
1)Create an asp.net web project. Name the project as ShowBinary
2) Add a file of type (.gif,.jpg,.doc,.xls) to the project
3) Specify a Start page for the application4) Use following code snippet in the form load event handler
Private Sub Page_Load(sender as object, e as System.EventArgs)
Response.ContentType = “Application/pdf” ‘ Specify Content Type
Dim fpath as string = Mappath(“Mypdf.pdf”) ‘ Specify Physical Path of the file
Response.writefile(fpath)
End Sub
ASP.NET 2.0 MultiView Control
<asp:MultiView ID="MultiView1" runat="server" >
<asp:View ID="View1" runat="server">This is one section where you can have a set of controls / contents<asp:View>
<asp:View ID="View2" runat="server">This is another section where you can have a different set of controls / contents<asp:View>
</asp:MultiView>
Now, to show the different tabs based on different events, we just need to set the following code:-
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}
"goto" Using Dotnet framework 2.0
{
Response.Write("Testing Goto");
goto Testing;
Testing:
Response.Write("Testing Goto in for loop");
}
output
Testing GotoTesting Goto in for loop
COALESCE using Sqlserver
now in new pl/sql version having the COALESCE function,
The magic of function is, it will automatically add "," seprator of employeelist.
///////////////////////////Before COALESCE ///
DECLARE @Emp_UniqueID int,
@EmployeeList varchar(100)
SET @EmployeeList = ''
DECLARE crs_Employees CURSOR
FOR SELECT Emp_UniqueID
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1
OPEN crs_Employees
FETCH NEXT FROM crs_Employees INTO @Emp_UniqueID
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @EmployeeList = @EmployeeList+CAST(@Emp_UniqueID AS varchar(5))+ ', '
FETCH NEXT FROM crs_Employees INTO @Emp_UniqueID
END
SET @EmployeeList = SUBSTRING(@EmployeeList,1,DATALENGTH(@EmployeeList)-2)
CLOSE crs_Employees
DEALLOCATE crs_Employees
SELECT @EmployeeLis
Output:
1, 2, 4
///////////////////////////After COALESCE/////////////
DECLARE @EmployeeList varchar(100)
SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') +
CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1
SELECT @EmployeeList
Output:1,2,4
/////////////////////////////////////////////////////////////////////////////
Anonymous delegate using Dotnet framework 2.0
{
System.Console.Write("hi");
});
Th.Start();
Breaking out a loop in two ways
1) firstway is using "break" keyword
2) Second way is using variable declaration.
//First way
for (int i = 0; i < 5; i++)
{
Response.Write("bala");
break;
}
//Second Way
bool br = false;
for (int j = 0; j < 2&& br == false; j++)
{
Response.Write("testingbala");
br = true;
}
Nullable DataType in Dotnet Framework 2.0
If you dont have the value for nullable datatype, it will return automatically null as a value.
Example 1:
int? var1 = null;
int var2 = 5;
var1 = var2;
if (var1.HasValue == true) //Using HasValue properties will will findout "var1" variable having value or null.
{
Response.Write("bala");
}
else
{
Response.Write("bala1");
}
Output:
bala
Example 2:
float? a = 436;
float? b = null;
if (a.HasValue) Response.Write("testing");
if (b.HasValue) Response.Write("testi"); else Response.Write("test");
Output:
testingtest
Tuesday, March 25, 2008
Calling Javascript in Dotnet based on Button id
<script language="javascript" type="text/javascript">
{
var con=confirm("Are sure want to delete this");
var test;
if(con==false)
{
alert("test");
}
else
{
alert("test1");
}
}
</script>
<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" />
In C# Page
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(btnsubmit, typeof(string), "bala", "Getconfirm();", true);
}
Note:btnsubmit is control id.