Wednesday, September 2, 2009

Set Session variable in javascript function


How can I set session variables with JavaScript ?

Sample Code In Java script:
<script language="javascript" type="text/javascript">
          function SendRequest() {
          var MySessionvalue = '<%= Session["EMP_C"] %>';
          var MyColocn = '<%= Session["COLOCN_C"] %>';
          alert(MySessionvalue);           
          }
< /script>

#How can I set session variables with JavaScript
#Assigning Session variable from Javascript
#How do i set a session variable using javascript?

Tuesday, August 11, 2009

OPENING NEW WINDOWS

var newwindow;
function openwindow(url)
{
newwindow=window.open(url,'name','height=800,width=600');
if (window.focus) {newwindow.focus()}
}

Wednesday, June 24, 2009

calculate hour minutes from milliseconds in oracle query

SQL QUERY:

SELECT
SUBSTR(to_char((39600/60/60),'00.00') , 0, INSTR(to_char((39600/60/60),'00.00'), '.', 1, 1)-1) hour,
to_char((SUBSTR(to_char((39600/60/60),'00.00'), INSTR(to_char((39600/60/60),'00.00'), '.', 1, 1),length(to_char((39600/60/60),'00.0'))) *60),'00') as Minutes
FROM dual;

OUTPUT

HOUR MINUTES
------ -------
11 00

1 rows selected

ANOTHER EXAMPLE

SELECT
SUBSTR(to_char((11700/60/60),'00.00') , 0, INSTR(to_char((11700/60/60),'00.00'), '.', 1, 1)-1) hour,
to_char((SUBSTR(to_char((11700/60/60),'00.00'), INSTR(to_char((11700/60/60),'00.00'), '.', 1, 1),length(to_char((11700/60/60),'00.00'))) *60),'00') as Minutes
FROM dual;

OUTPUT

HOUR MINUTES
------ -------
03 15

1 rows selected

Friday, June 5, 2009

FILL DATA USING ORACLE STORE PROCEDURE IN ASP.NET C#

PROCEDURE "GET_ALL_AREA"

(

ITEMS_CURSOR OUT SYS_REFCURSOR

)

is


BEGIN

OPEN ITEMS_CURSOR FOR SELECT AREAID,AREANAME,AREAPINCODE FROM AREA;


END;


DataSet ds = new DataSet();

OracleCommand command = new OracleCommand();

command.CommandType = CommandType.StoredProcedure;

command.CommandText = “Get_All_Area”;

command.Connection = conn.Get_Connection();

command.Parameters.Add("ITEMS_CURSOR", OracleType.Cursor ).Direction = ParameterDirection.Output;

OracleDataAdapter adpt = new OracleDataAdapter(Command);

adpt.Fill(ds, str_table);

Close_Connection();

public string Connection_String

{

get

{

return ConfigurationSettings.AppSettings["dbConnectionString"];

}

}

//Function For Open New Connection

public OracleConnection Get_Connection()

{

try

{

OracleConn = new OracleConnection(Connection_String);

OracleConn.Open();

}

catch (Exception ex)

{

throw ex;

}

return OracleConn;

}

//Close Connection

public void Close_Connection()

{

try

{

OracleConn.Close();

}

catch(Exception ex)

{

throw new Exception(ex.Message, ex);

}

}

CONVERT TEXT INTO INITCAP IN C#

public static string PropCase(string strText)

{

return new CultureInfo("en").TextInfo.ToTitleCase(strText.ToLower());

}

Monday, May 25, 2009

How To Generate IFrame At Runtime Using Javascript


<script type="text/javascript">
var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
el.setAttribute('width', '100%');
document.body.appendChild(el);
el.setAttribute('src', 'http://www.yahoo.com');
script>

Thursday, May 14, 2009

How to Print Div Tag Using Javascript?



HTML FILE :

<script language="javascript">

function CallPrint( strid )

{

var prtContent = document.getElementById( strid );

var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,toolbar=1,scrollbars=1,status=0');

WinPrint.document.write( prtContent.innerHTML );

WinPrint.document.close();

WinPrint.focus();

WinPrint.print();

WinPrint.close();

prtContent.innerHTML=strOldOne;

}

script>

<div id="print_Grid">

This is Print

This is Print

This is Print

This is Print

This is Print

div>



Code FILE :


protected void Page_Load(object sender, EventArgs e)

{

btnPrint.Attributes.Add("onclick", "javascript:CallPrint('print_Grid')");

}


How To Use This Code?

1. Copy JavaScript into your HTML Page

2. Make a Div Tag Which data you want to print into that div tag

3. Add Print Button and call JavaScript Function




Wednesday, May 13, 2009

How To Get List of Tables in SQL Server


Using Following SQL Query you can get list of tables in SQL Database

SELECT name [Table Name]
FROM sysobjects
WHERE xtype = 'U'



How to Get SQL Table Columns List

How to get all field names in a table using sql query?



Following query is use for getting all sql table column names from database in Microsoft SQL server.

SELECT c.name
FROM syscolumns c INNER JOIN sysobjects o ON o.id = c.id
WHERE o.name ='TABLENAME'
ORDER BY colid

#How to find all SQL tables with a column name
#How to Get SQL Table Columns List
#How to get all field names in a table using sql query

Thursday, April 23, 2009

sql query for Generate serial no



SELECT C.EmployeeId, C.FirstName,C.LastName,

(SELECT COUNT(*) FROM Employee C2 WHERE C2.EmployeeId <= C.EmployeeId

) as SrNoFROM Employee C ORDER BY EmployeeId

Friday, April 17, 2009

restrict delete record which is used in other table in mssql

1. Create Scalar value Function in sql
ex:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



create FUNCTION [dbo].[GetApplicationDelete]
(
@ApplicationId numeric(18,0)
)
RETURNS bit
AS
BEGIN
-- Declare the return variable here
DECLARE @flg as bit;
declare @count as numeric(18,0);

-- Add the T-SQL statements to compute the return value here
select @count = SUM(b) from
(
SELECT count(*) b from dbo.ApplicationApprover
where ApplicationId = @ApplicationId
union
select count(*) b from .dbo.Cases
where ApplicationId = @ApplicationId



) tablename

if @count = 0
set @flg =1;
else
set @flg =0;


-- Return the result of the function
RETURN @flg

END

2 .Use this function in Sql Query

Ex:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go




create PROCEDURE [dbo].[APPLICATION_FindAll]
AS
SET NOCOUNT ON

SELECT
ApplicationId,
AppCode,
AppName,
Description,
Remarks,
AppType,
IsActive,
IsDelete,
AppStartdate,
AppEnddate,
CreateBy,
CreateDate,
UpdateBy,
UpdateDate,
[dbo].GetApplicationDelete(ApplicationId) delflg
FROM [APPLICATION]

GO

3. Apply in Form in Grid View Delete Button
<asp:TemplateField HeaderText="Delete">

<ItemTemplate>

<asp:ImageButton ID="imgbtnDelete" runat="server" AlternateText="Delete" CausesValidation="False"

CommandName="Delete" ImageUrl="~/App_Themes/Image/Delete.gif" OnClientClick="Are You Sure?"

Visible='<%# Eval("delflg") %>' />

</ItemTemplate>

<ItemStyle HorizontalAlign="Center" />

</asp:TemplateField>

Wednesday, April 1, 2009

confirmation message on delete in a gridview

protected void gridOverview_OnRowDataBound(object sender, GridViewRowEventArgs e)
//Add delete msgbox to each row containing field
//information to identify the row
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// reference the Delete ImageButton
ImageButton ib = (ImageButton)e.Row.FindControl(“ibDelete”);
ib.Attributes.Add(“onclick”,“javascript:return ” +
confirm(’Are you sure about deleting ” +
DataBinder.Eval(e.Row.DataItem, ColomnName) + “?’);”);
}
}

OR


Add New Client Click property of button
return confirm(’Are you sure about deleting ”);

OR
Use Ajax Extender for confirmation box
<asp:TemplateField HeaderText=”Delete” >
<ItemStyle CssClass=”grid-column-buttons” />
<ItemTemplate>
<asp:ImageButton ID=”ibDelete” runat=”server”
CausesValidation=”False” CommandName=”Delete”
ImageUrl=”~/Images/icon-delete.gif” />
<ajaxToolkit:ConfirmButtonExtender ID=”ConfirmBtExt1″
runat=”server” TargetControlID=”ibDelete”
ConfirmText=’Are you sure about deleting this record?’ />
ItemTemplate>
asp:TemplateField>


Wednesday, March 25, 2009

HOW TO BIND DROPDOWN LIST & ADD NEW VALUE

clsItemGroupMast_CDO ItemGroupMast_CDO = new clsItemGroupMast_CDO();
clsItemGroupMast_DA ItemGroupMast_DA = new clsItemGroupMast_DA();
DataSet ds = new DataSet();

ds = ItemGroupMast_DA.View_ItemGroupMast(ItemGroupMast_CDO);
ddlProductGroup .DataSource = ds;
ddlProductGroup.DataTextField = "GroupName";
ddlProductGroup.DataValueField = "GroupId";
ddlProductGroup.DataBind();
ddlProductGroup.Items.Add("--Select--");
ddlProductGroup.Items.FindByText("--Select--").Value = "0";
ddlProductGroup.SelectedIndex = -1

Wednesday, March 18, 2009

Types of SQl Join

The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.
Tables in a database are often related to each other with keys.
A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
Look at the "Persons" table:
P_Id LastName FirstName Address City
1 Rajesh Ahmedabad Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
Note that the "P_Id" column is the primary key in the "Persons" table. This means that no two rows can have the same P_Id. The P_Id distinguishes two persons even if they have the same name.
Next, we have the "Orders" table:
O_Id OrderNo P_Id
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15
Note that the "O_Id" column is the primary key in the "Orders" table and that the "P_Id" column refers to the persons in the "Persons" table without using their names.
Notice that the relationship between the two tables above is the "P_Id" column.

Different SQL JOINs

Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.
  • JOIN: Return rows when there is at least one match in both tables
  • LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
  • RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
  • FULL JOIN: Return rows when there is a match in one of the tables

The INNER JOIN keyword return rows when there is at least one match in both tables.

SQL INNER JOIN Syntax

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
PS: INNER JOIN is the same as JOIN.

SQL INNER JOIN Example

The "Persons" table:
P_Id LastName FirstName Address City
1 Rajesh Ahmedabad Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
The "Orders" table:
O_Id OrderNo P_Id
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15
Now we want to list all the persons with any orders.
We use the following SELECT statement:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName 
The result-set will look like this:
LastName FirstName OrderNo
Rajesh Ahmedabad 22456
Rajesh Ahmedabad 24562
Pettersen Kari 77895
Pettersen Kari 44678
The INNER JOIN keyword return rows when there is at least one match in both tables. If there are rows in "Persons" that do not have matches in "Orders", those rows will NOT be listed.

SQL LEFT JOIN Keyword

The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).

SQL LEFT JOIN Syntax

SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
PS: In some databases LEFT JOIN is called LEFT OUTER JOIN.

SQL RIGHT JOIN Keyword

The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).

SQL RIGHT JOIN Syntax

SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
PS: In some databases RIGHT JOIN is called RIGHT OUTER JOIN.

SQL FULL JOIN Keyword

The FULL JOIN keyword return rows when there is a match in one of the tables.

SQL FULL JOIN Syntax

SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name

send mail using gmail in asp.net

If we don’t have SMTP server for sending mails at that time we can send mails by using gmail smtp server in asp.net. I will show to how to implement mail sending concept using Gmail credentials in asp.net. To implement this concept first you need to enable POP enable in your Gmail account for sending emails.


// **
CALL FUNCTION FOR SEND MAIL
**//
SendMail("smtp.gmail.com",
465,
"testemail@gmail.com",
"test[wd",
"Rajesh Prajapati",
"testemail@gmail.com",
"Rajesh",
"testemail@yahoo.co.in",
"Test",
"Hello!",
true);

//**
FUNCTION FOR SENDING MAIL USING GMAIL ACCOUNT

**//
public static void SendMail(string sHost, int nPort, string sUserName, string sPassword, string sFromName, string sFromEmail, string sToName, string sToEmail, string sHeader, string sMessage, bool fSSL)
{
if (sToName.Length == 0)
sToName = sToEmail;
if (sFromName.Length == 0)
sFromName = sFromEmail;

System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
if (fSSL)
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

if (sUserName.Length == 0)
{
//Ingen auth
}
else
{
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
}

Mail.To = sToEmail;
Mail.From = sFromEmail;
Mail.Subject = sHeader;
Mail.Body = sMessage;
Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

System.Web.Mail.SmtpMail.SmtpServer = sHost;
System.Web.Mail.SmtpMail.Send(Mail);
}

How To Get Applocation setting Varible

Web.Config

"< appSettings >
< add key = SqlServerConnectionString" value="Server=.\sqlexpress;UID=test;PWD=test;Database=test " />
< / appSettings >"


Use Configuration


return ConfigurationSettings.AppSettings["SqlServerConnectionString"]

ShareThis

Welcome

Welcome to Rajesh Prajapati, asp.net blog.
Here you can find some useful code and information about asp.net., c#, VB.net, SQL Server, Web Service, Web Designing etc