NetProgrammingHelp.com

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

Recent Posts

  • How to Insert a XML Data into Sql Table Using OPENXML SQL SERVER
  • Creating Writing Reading Saving a File Using Sql server
  • Import CSV into SQL/BULK INSERT
  • Exporting Copying Sending Sql Table data into Excel Using OpenRowSet/Sql Server
  • Calling Accessing Web Services/Web methods Using JQuery
  • Adjusting Resizing Iframe Based On Screen resolution
  • Dynamically Updating Fetching Editing Printing Table Column/Column Names Using Oracle/ref cursor
  • Delete Remove Clear All Cookies Using Asp.Net
  • Disable Avoid Browser Back Button Functionality Using JavaScript Asp.Net
  • Sending Bulk Asynchronous mail using asp.net/c#
  • How to Insert a XML Data into Sql Table Using OPENXML SQL SERVER

    Posted by James Add Comments

    Introduction:
    In this article, i am going to explain about how to insert a data into sql table using OpenXml/Sql Server.

    Main:

    OPENXML provides a rowset view over an XML document.OPENXML allows you to read xml strings,

    syntax for OPENXML,

    OPENXML(idoc int[input],rowpattern varchar[input],[flags byte[input])
    WITH (SchemaDeclaration | TableName)]
     
    DECLARE @idoc int
    DECLARE @doc varchar(8000)
    SET @doc ='<ROOT><EMP>
    <id>1</id>
    <name>James</name>
    <age>32</age>
    </EMP>
    <EMP>
    <id>2</id>
    <name>Chris</name>
    <age>42</age>
    </EMP>
    <EMP>
    <id>3</id>
    <name>Peter</name>
    <age>23</age>
    </EMP>
    <EMP>
    <id>4</id>
    <name>Andrea</name>
    <age>12</age>
    </EMP>
    <EMP>
    <id>5</id>
    <name>Christopher</name>
    <age>75</age>
    </EMP>
    </ROOT>'
     
    --Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    -- Execute a SELECT statement that uses the OPENXML rowset provider.
    Insert into EMP_Details SELECT id, name, age from 
    OPENXML (@idoc, '/ROOT/EMP',2)
    WITH (id  int, name varchar(50), age int)
     
    Select * from EMP_Details

    Conclusion:
    Hope this helps,
    Happy Coding.

    Creating Writing Reading Saving a File Using Sql server

    Posted by James Add Comments

    Introduction:
    In this article, i am going to explain about how to create,write,save a file using sql server.

    Main:

    The below predefined stored procedure allows you to write a file under sql server filesystem.Just give the filename as input(File you wants to create under file system).

    Create Procedure  [dbo].[NetProgrammingHelp_SaveFile](@text as NVarchar(Max),@Filename Varchar(200)) 
    AS 
    Begin 
     
    declare @Object int,
            @rc int, -- the return code from sp_OA procedures 
            @FileID Int 
     
    EXEC @rc = sp_OACreate 'Scripting.FileSystemObject', @Object OUT 
    EXEC @rc = sp_OAMethod  @Object , 'OpenTextFile' , @FileID OUT , @Filename , 2 , 1 
    Set  @text = Replace(Replace(Replace(@text,'&','&'),'<' ,'<'),'>','>')
    EXEC @rc = sp_OAMethod  @FileID , 'WriteLine' , Null , @text  
    Exec @rc = master.dbo.sp_OADestroy @FileID   
     
    Declare @Append  bit
    Select  @Append = 0
     
    If @rc <> 0
    Begin
        Exec @rc = master.dbo.sp_OAMethod @Object, 'SaveFile',null,@text ,@Filename,@Append
     
    End
     
    Exec @rc = master.dbo.sp_OADestroy @Object 
     
    End 
     
    EXEC NetProgramming_SaveFile 'Microsoft SQL Server 2008', 'C:MSSQL.txt'

    Conclusion:
    Hope this helps.
    Happy Coding.

    Import CSV into SQL/BULK INSERT

    Posted by James Add Comments

    Introduction:
    In this article,i am going to explain about how to import the CSV data into SQL table.

    Main:
    Bulk Insert Option allows you to insert bulk data’s into sql server table.

    For more info about Bulk Insert please visit here,

    For ex,

    BULK INSERT EMP
    FROM 'c:\EMPDetails.csv'  -- Full path of the CSV file
    WITH
    (
    FIELDTERMINATOR = ',', --CSV field delimiter
    ROWTERMINATOR = '\n'   --Use to shift the control to next row
    )
     
    select * from EMP;

    Conclusion:
    Hope this helps,
    Happy Coding.

    Exporting Copying Sending Sql Table data into Excel Using OpenRowSet/Sql Server

    Posted by James Add Comments

    Introduction:
    In this article,iam going to explain about how to export a sql table data into sql server using sql server 2008.

    Main:
    Before starting first we need to set the below configuration settings,

    EXEC sp_configure 'show advanced options', 1;
    GO RECONFIGURE;
    GO EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
    GO RECONFIGURE;

    The config option EXEC sp_configure ‘Ad Hoc Distributed Queries’, 1 allows you to run all open rowset queries,

    INSERT INTO OPENROWSET 
    ('Microsoft.Jet.OLEDB.4.0', 
     'Excel 8.0;Database=c:Emp_Details.xls;',
     'SELECT * FROM [Sheet1$]')SELECT * FROM EMP
     
    For (.XLSX) format
    INSERT INTO OPENROWSET ('Microsoft.ACE.OLEDB.12.0', 
                            'Excel 8.0;Database=c:Emp_Details.xlsx;'
                           ,'SELECT * FROM [Sheet1$]')SELECT * FROM EMP

    Conclusion:
    Hope this helps,
    Happy Coding.

    Calling Accessing Web Services/Web methods Using JQuery

    Posted by James Add Comments

    Introduction:
    In this article,i am going to explain about, how to call a Web service web method using Jquery.

    Main:
    The below attribute allows us to access the web method using client side programming,

    [System.Web.Script.Services.ScriptService]
     
     
    function WebService()
            {
                $.ajax({
                    type: "POST",  //Method
                    url: "Add.asmx/Addnumbers",  //Webservice page/Web method
                    data: "{int a,int b}", //Parameters list
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    error: OnError
                });
            }
     
            function OnSuccess(data, status) 
            {
                Alert(data.d);
            }
     
            function OnError(request, status, error)
            {
                Alert(request.statusText);
            }

    Conclusion:
    Hope this helps,
    Happy Coding.

    Adjusting Resizing Iframe Based On Screen resolution

    Posted by James Add Comments

    Introduction:
    In this article,i am going to explain how to adjusting iframe size based on screen resolution or its contents,

    Main:

    <html>
    <body OnLoad = "AdjustSize();">
    <div id="FrameDiv" Height="440px">
    <iframe id="Frame" src="WebForm1.html">
    </iframe>
    </div>
    </body>
    </html>
     
     
    function AdjustSize()
    {
    if ((screen.width>=1024) && (Screen.height>=768)){
    document.getElementById('Frame').style.height =
    Frame.document.body.scrollHeight + 10;
    }
    }

    Conclusion:
    Hope this helps,
    Happy Coding.

    Dynamically Updating Fetching Editing Printing Table Column/Column Names Using Oracle/ref cursor

    Posted by James Add Comments

    Introduction:
    In this article i am going to explain how to dynamically updating fetching oracle dynamic table columns.

    Main:

    declare 
    t_tablename CHAR := dyn_20101980;  //Just Pass yours dynamic table
    result_cv IN OUT ref_cursor;
    t_column_name VARCHAR2(100);
    t_column_list VARCHAR2(100);
    t_query VARCHAR2(100);
     
    CURSOR col_cur
    IS
    SELECT column_name
    FROM all_tab_columns
    WHERE table_name = t_tablename;
     
    BEGIN
    OPEN col_cur;
     
    LOOP
    FETCH col_cur
    INTO t_column_name;
     
    EXIT WHEN col_cur%NOTFOUND;
     
    IF t_column_name = 'SALARY_DETAILS'
    THEN
    t_column_name := (|| t_column_name || * 100/10')SALARY'; //Just foramtting headers and values
    END IF;
     
    IF t_column_list IS NULL
    THEN
    t_column_list := 'SELECT' || t_column_name;
    ELSE
    t_column_list := t_column_list || ',' || t_column_name;
    END IF;
    END LOOP;
     
    t_column_list := t_column_list || 'FROM' || t_tablename;
     
    OPEN result_cv FOR t_column_list;
    END;

    Conclusion:
    Hope this helps,
    Happy Coding.

    Delete Remove Clear All Cookies Using Asp.Net

    Posted by James Add Comments

    Introduction:
    In this article,i am going to explain about how to delete all the cookies in particular machine using asp.net

    Main:
    Sometimes in secure webpages,we need to clear all client side entries.The below server side code will clear all cookie entries.

    string[] Cookentries = Request.Cookies.AllKeys;
    foreach (string local_cookie in Cookentries)
    { 
    Response.Cookies[local_cookie].Expires = DateTime.Now.AddDays(-1);
    }

    Conclusion:
    Hope this helps,
    Happy Coding.

    Disable Avoid Browser Back Button Functionality Using JavaScript Asp.Net

    Posted by James one Commented

    Introduction:
    In this article i am going to explain about how to disable avoid browser back button functionality using javascript asp.net.

    Main:

    We can easily avoid the navigation of previous page(using browser back button) using the below simple script,

    <script type = "text/javascript" >
    function InvalidBackButton()
    {
    window.history.forward();
    }
    setTimeout("InvalidBackButton()", 0);
    </script>

    If you wants in Code Behind,

    string local_exestring = "&lt;SCRIPT language=javascript&gt;n";
    local_exestring += "window.history.forward(1);n";
    local_exestring += "n";
    <strong>ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "Script",local_exestring );</strong>

    Conclusion:
    Hope this helps,
    Happy Coding.

    Sending Bulk Asynchronous mail using asp.net/c#

    Posted by James Add Comments

    Introduction:
    In this i am going to explain how to send a mail more than one client asynchronously using Asp.Net/c#.

    Main:
    Normally we using smtp.Send for sending smtp mails,For asynchronous mail communication we have a new option
    in asp.net2.0 called sendasync.

    MailMessage NetProgrammingHelp_Mail = new MailMessage();
    NetProgrammingHelp_Mail.To.Add("netprogramminghelp@gmail.com");
    NetProgrammingHelp_Mail.To.Add("silverlightscripting@gmail.com");
    NetProgrammingHelp_Mail.From = new MailAddress("sample@gmail.com");
    NetProgrammingHelp_Mail.Subject = "Hi,This is my mail with attachment";
    NetProgrammingHelp_Mail.Body = "Enjoy this Code";
    NetProgrammingHelp_Mail.IsBodyHtml = true;
    NetProgrammingHelp_Mail.Attachments.Add(new Attachment(@"C:\sample.txt", sample.txt));
    SmtpClient smtp = new SmtpClient();
    object local_status = mail;
    smtp.Host = "SmtpNetProgrammingHelp.com"; 
    smtp.Credentials = new System.Net.NetworkCredential
    ("NetProgrammingHelp_MailID@gNetProgrammingHelp_Mail.com", "NetProgrammingHelp_MailPassword");  //Use yours own userid and password,for ex,gmail userid and password.
    smtp.EnableSsl = true;
    smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);       
    smtp.SendAsync(mail, local_status);
     
     
    public void smtp_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            MailMessage mail = e.UserState as MailMessage;
            if (!e.Cancelled && e.Error!=null)        {
                Response.Write("Mail sent successfully");
            }
        }

    Conclusion:
    Hope this helps,
    Happy Coding.

    Software