Tuesday, June 19, 2012

How to use ajax(Page Method) by using jquery


How to use ajax(Page Method) by using jquery  

<script type="text/javascript">
 function ChangeStatusOrder(ID, action,confirmationType ) {
            
            $.ajax({
                type: "POST",
                url: "TransactionStatusMaster.aspx/UpdateCurrentOrder" ,
                data: "{id:" + ID + ",action:" + action + ",confirmation:'" + confirmationType + "'}" ,
                contentType: "application/json; charset=utf-8" ,
                dataType: "json",
                success: function (msg) {
                    // Do something interesting here.
                   
                   
                }
            });


        }
  

 </script >
 
  TransactionStatusMaster.aspx
==============================
      <img src="../../Assets/Images/arrow_up.png" onclick="ChangeStatusOrder(<% #Eval("ID") %>,0,'<% #Eval("ASGroup") %>')"
                        alt="Move Up" style="cursor : pointer;" />

TransactionStatusMaster.aspx.cs:
================================
  [System.Web.Services. WebMethod]
        public static string UpdateCurrentOrder( int id,int action,string confirmation)
        {
            
            //perform your action here

            return "your success message";

        }

Send Email From SQL Server

Today in this article I would discuss about the Database Mail which is used to send the Email using SQL Server.  Previously I had discussed about SQL SERVER – Difference Between Database Mail and SQLMail. Database mail is the replacement of the SQLMail with many enhancements. So one should stop using the SQL Mail and upgrade to the Database Mail. Special thanks to Software Developer Monica, who helped with all the images and extensive testing of subject matter of this article.
In order to send mail using Database Mail in SQL Server, there are 3 basic steps that need to be carried out. 1) Create Profile and Account 2) Configure Email 3) Send Email.
Step 1) Create Profile and Account:
You need to create a profile and account using the Configure Database Mail Wizard which can be accessed from the Configure Database Mail context menu of the Database Mail node in Management Node. This wizard is used to manage accounts, profiles, and Database Mail global settings which are shown below:




Step 2) Configure Email:
After the Account and the Profile are created successfully, we need to configure the Database Mail. To configure it, we need to enable the Database Mail XPs parameter through the sp_configure stored procedure, as shown here:
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO
Step 3) Send Email:
After all configurations are done, we are now ready to send an email. To send mail, we need to execute a stored procedure sp_send_dbmail and provide the required parameters as shown below:
USE msdb
GO
EXEC sp_send_dbmail @profile_name='PinalProfile',
@recipients='test@Example.com',
@subject='Test message',
@body='This is the body of the test message.
Congrates Database Mail Received By you Successfully.'
After all validations of the parameters entered are done, certain stored procedures are executed and the mail is queued by Service Broker, read more at SQL SERVER – Introduction to Service Broker.
Database Mail keeps copies of outgoing e-mail messages and displays them in the sysmail_allitems, sysmail_sentitems, sysmail_unsentitems, sysmail_faileditems . The status of the mail sent can be seen in sysmail_mailitems table, when the mail is sent successfully the sent_status field of the sysmail_mailitems table is set to 1 which can again be seen in sysmail_sentitems table. The mails that are failed will have the sent_status field  value to 2 and those are unsent will have value 3.
The log can be checked in sysmail_log table as shown below:
SELECT *
FROM sysmail_mailitems
GO
SELECT *
FROM sysmail_log
GO
Status can be verified using sysmail_sentitems table.
After sending mail you can check the mail received in your inbox, just as I received as shown below.

Source: sqlauthority.com

SQL basics

Create New Database:
===================

1. right click on "Databases" folder and click on "Create new Database" then it will shows dialog then enter database name and then click ok
after clicking ok new database created with the given database name under databases

Creating Table:
===============
2.  expand  your database and right click on tables and click on "New Table" then give your columns with appropriate datatype and save table with your table name click on ok. Now new table created under the tables with the given table name

Selecting Data:
==============
   3. Select * from tablename

Inserting Data:
==============

    4. Inserting values into the existing table

    Insert into tablename(column1,column1) values(1,'test');
  
    result:  1 row(s) inserted sucessfully

Updating Data:
==============

    4. Updating  existing table data

    Update tablename SET column2='testt' where column1=2
  
    result:  1 row(s) Updated sucessfully


Delete Data:
==============

    4.deleting  existing table data
  
    delete from tablename   where column1=2

DELETE ALL The Stored Procedures In SQL Server

USE [db_name]

CREATE PROCEDURE dbo.__DeleteAllProcedures
As
declare @procName varchar(500)
-- Removes stored procedures
declare cur cursor
for select [name] from sys.objects where [type] = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
if @procName <> '__DeleteAllProcedures'
exec('drop procedure ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur

-- Removes Views
declare cur cursor
for select [name] from sys.objects where [type] = 'v'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop view ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur

-- Removes Functions
declare cur cursor
for select [name] from sys.objects WHERE [type] = 'fn'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop function ' + @procName)
fetch next from cur into @procName
end
close cur
deallocate cur

-- removes itselfs
DROP PROCEDURE __DeleteAllProcedures

Go

exec __DeleteAllProcedures 

How To Customize Gridview Inbuild Templates


Example:
=======
 grvDynamicResult.Templates.EmptyDataRow = new SimilarSearchTemplate ();

SimilarSearchTemplate.cs
==================
    public class SimilarSearchTemplate : ITemplate
    {

        
        public SimilarSearchTemplate()
        {

          

        }

        public void InstantiateIn(Control container)
        {

            Table table = new Table();
            table.Style.Add( "width", "100%" );
            table.Style.Add( "text-align", "center" );
            TableRow tr = new TableRow();
             TableRow tr2 = new TableRow();

          
            HyperLink lnkShowPhoneticSearch = new   HyperLink ();
                lnkShowPhoneticSearch.Text = "Click here to get similar Records." ;
              
                lnkShowPhoneticSearch.Style.Add( "cursor", "pointer" );

                 Label lblNoData = new Label ();
                lblNoData.Text = "No data to display";
                TableCell cell = new TableCell();
                cell.Controls.Add(lnkShowPhoneticSearch);

                TableCell cell1 = new TableCell();
                cell1.Controls.Add(lblNoData);
                tr.Cells.Add(cell);
                tr2.Cells.Add(cell1);

             
                table.Rows.AddAt(0, tr);
                table.Rows.AddAt(0, tr2);

            container.Controls.Add(table);
        }
    }

How to check default Email Client in C#


How to check default Email Client exist or not 
==============================================
 object mailClient = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail" , "", "none");
    

//ex: here mailClient  will be MicroSoft Outlook 

We can remove duplicate entries by using ".Distinct()" in arraylist

We can remove duplicate entries  by using ".Distinct()" in arraylist

Example:
======

I have createdby column exist in testtable which have more one row exist with 5 duplicate entries. i have to get only one row
 


  
   ID   Createdby
    ===  ========
      1    Reddy
      2    Reddy
      3    Reddy
      4    Reddy

In above thing i need to select only one "Reddy"



DataTable table=new DataTable("MyTable");//Actually i am getting this table data from database

DataColumn col=new DataColumn("Createdby");

var  childrows =  table.AsEnumerable().Select( row => row.Field<object>(col)).Distinct().ToArray();