Tuesday, 16 April 2013

aspnet_regsql.exe

GO to windows link


c:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe
sql/ visual stidio command promt type this
aspnet_regsql.exe -S <Server> -U <Username> -P <Password> -ed -d Northwind

other solution
aspnet_regsql -d <databasename> -ssadd -sstype c -U <username>

Tuesday, 9 April 2013

BackgroundWorker in c#


Creating a BackgroundWorker
We can create the BackgroundWorker at design-time by dragging onto a Form or at run-time using the BackgroundWorker class.  The following code is added when you drag a BackgroundWorker component onto a Form.
private System.ComponentModel.BackgroundWorker backgroundWorker1;
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); 
BackgroundWorker Properties
Here is a list of BackgroundWorker class properties.
CancellationPending - Indicates if an application has requested cancellation of a BackgroundWorker.
IsBusy - Indicates if a BackgroundWorker is running an asynchronous operation.
WorkerReportsProgress - Indicates of a BackgroundWorker can report progress updates.
WorkerSupportsCancellation - Indicates if a BackgroundWorker supports asynchronous cancellation.

Methods
BackgroundWorker has two methods, RunWorkerAsync and CancelAsync. The RunWorkerAsync starts the thread and the CancelAsync stops the thread.
Events
DoWork event is the starting point for a BackgroundWorker. This event is fired when the RunWorkerAsync method is called. In this event hander, we call our code that is being processed in the background where our application is still doing some other work.
this.backgroundWorker1.DoWork += newSystem.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);

The DoWork event handler looks like this where we need to call our time-consuming method.
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundProcessLogicMethod();
}

ProgressChanged event occurs when ReportProgress is called.

RunWorkerCompleted event occurs when the background operation has completed.

Working Sample
Now we are going to create a sample application. The user interface looks like Figure 1 where a Form has two Button controls and a RichTextBox control. While BackgroundWorker will be doing some background work, user can still type in the RichTextBox.

BackgroundWorkerImg.jpg
Figure 1

Start button click starts the processing BackgroundWorker and Stop button click stops the processing. While BackgroundWorker is doing work in the background, you may still type anything in the RichTextBox control.

The Start and Stop button click event handlers looks like this.

private void StartButton_Click(object sender, EventArgs e)
{
    // Start BackgroundWorker
    backgroundWorker1.RunWorkerAsync(2000);
}

private void StopButton_Click(object sender, EventArgs e)
{
    // Cancel BackgroundWorker
    if (!backgroundWorker1.IsBusy)
        backgroundWorker1.CancelAsync();
}

And here is the code for the DoWork event, background worker method and WorkerCompleted event.

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundWorker helperBW = sender as BackgroundWorker;
    int arg = (int)e.Argument;
    e.Result = BackgroundProcessLogicMethod(helperBW, arg);
    if (helperBW.CancellationPending)
    {
        e.Cancel = true;
    }
}

// Put all of background logic that is taking too much time
private int BackgroundProcessLogicMethod(BackgroundWorker bw, int a)
{
    int result = 0;
    Thread.Sleep(20000);
    MessageBox.Show("I was doing some work in the background.");
    return result;
}

private void backgroundWorker1_RunWorkerCompleted(object sender,
    RunWorkerCompletedEventArgs e)
{
    if (e.Cancelled) MessageBox.Show("Operation was canceled");
    else if (e.Error != null) MessageBox.Show(e.Error.Message);
    else MessageBox.Show(e.Result.ToString());
}  

Tuesday, 12 February 2013

Row Number, rank, dense rank example


with salTable as(
select lastName, ROW_NUMBER() over (order by salesYDT desc)as rankof, SalesYDT from SalesPerson
)
select * from salTable where rankof=2
------------------------------------------------
SELECT s.LastName,
ROW_NUMBER() OVER (ORDER BY s.SalesYDT) AS 'Row Number',
RANK() OVER (ORDER BY s.SalesYDT) AS 'Rank',
DENSE_RANK() OVER (ORDER BY s.SalesYDT) AS 'Dense Rank',
NTILE(4) OVER (ORDER BY s.SalesYDT) AS 'Quartile',
CAST(s.SalesYDT AS INT) SalesYDT, s.PostalCode
FROM SalesPerson s
WHERE
 SalesYDT <> 0;
 ------------------------------------------
 SELECT top 20 *
FROM SalesPerson
ORDER BY SalesYDT OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY







USE [master]
GO

/****** Object:  Table [dbo].[SalesPerson]    Script Date: 02/12/2013 16:52:06 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[SalesPerson](
      [lastName] [varchar](200) NULL,
      [SalesYDT] [decimal](18, 2) NULL,
      [PostalCode] [nchar](10) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


Friday, 18 January 2013

sql server deleted record recover


go to link-
http://raresql.com/tag/recover-deleted-data-from-sql-server/

create stote proc and check all dleetd records
plxz click for above link



Select [RowLog Contents 0]
FROM   sys.fn_dblog(NULL, NULL)
WHERE  AllocUnitName = 'dbo.admin_Login'
       AND Context IN ( 'LCX_MARK_AS_GHOST', 'LCX_HEAP' )
       AND Operation in ( 'LOP_DELETE_ROWS' )

Friday, 4 January 2013

sql server delete or drop all tables


DECLARE @table_schema varchar(100)
       ,@table_name varchar(100)
       ,@constraint_schema varchar(100)
       ,@constraint_name varchar(100)
       ,@cmd nvarchar(200)

DECLARE table_cursor CURSOR FOR

select TABLE_SCHEMA, TABLE_NAME
from INFORMATION_SCHEMA.TABLES
where TABLE_NAME != 'sysdiagrams'

OPEN table_cursor

FETCH NEXT FROM table_cursor INTO @table_schema, @table_name



WHILE @@FETCH_STATUS = 0

BEGIN
SELECT @cmd = 'DELETE' + @table_schema + '.' + @table_name
--SELECT @cmd = 'DROP TABLE ' + @table_schema + '.' + @table_name

EXEC sp_executesql @cmd


FETCH NEXT FROM table_cursor INTO @table_schema, @table_name

END



CLOSE table_cursor

DEALLOCATE table_cursor

Wednesday, 26 December 2012

gridview data download in asp.net


gridview print as design show on the form
in asp.net.


you can   download the show data on grid or listview or any control in aps.net. just change bold and underline.

 protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=myexcelfile.doc");
            Response.ContentType = "application/vnd.xls";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }

Friday, 21 December 2012

Image code with sql server


Image Insert /Retrieve  with  sql server Database Table
Asp.net code insert image by  code
cmd.Parameters.Add("@ProductPicture", SqlDbType.VarBinary).Value = uploadProduct.FileBytes;

retrieve image from sql server databse
we take new asp.net page and convert byte to response. BinaryWrite

<asp:Image ID="Image1" runat="server" ImageUrl='<%# "GetProductPicture.aspx?ProductID=" + Eval("ProductID")%>' alt="Image" Width="150px" Height="100px" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1" style="border-radius:5px;" />

Now productPicture page code
protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = null;
        try
        {
           int Prod_Id = Convert.ToInt32(Request.QueryString["ProductID"].ToString());
          con = new SqlConnection(ConfigurationManager.AppSettings["AsCon"].ToString());
            if (con != null)
            {
                con.Open();
            }
            SqlCommand cmd = new SqlCommand("select ProductPicture from ProductMaster where ProductID=" + Prod_Id + "", con);
            byte[] product = (byte[])cmd.ExecuteScalar();
            Response.BinaryWrite(product);
        }
        catch (Exception ex)
        {
           // Mailer.SendTechnicalMail(ex.Message);
        }
        finally
        {
            if (con != null)
            {
                con.Close();
            }
        }
    }

Thursday, 20 December 2012

message box show in asp.net

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// Summary description for MessageBox
/// </summary>
public class MessageBox
{
    // Lets keep the message coming from all the pages here
    static Dictionary<Page, Queue> pageTable = null;
   
    static MessageBox()
    {
        // Create the store
        pageTable = new Dictionary<Page, Queue>();
    }

    public static void Show(string str)
    {
        // Lets find out what page is sending the request
        Page page = HttpContext.Current.Handler as Page;

        // If a valid page is found
        if (page != null)
        {
            // Check if this page is requesing message show for the first time
            if (pageTable.ContainsKey(page) == false)
            {
                // Lets create a message queue dedicated for this page.
                pageTable.Add(page, new Queue());
            }

            // Let us add messages of this to the queue now
            pageTable[page].Enqueue(str);

            // Now let put a hook on the page unload where we will show our message
            page.Unload += new EventHandler(page_Unload);
        }       
    }

    static void page_Unload(object sender, EventArgs e)
    {
        // Lets find out which page is getting unloaded
        Page page = sender as Page;

        // If a valid page is founf
        if (page != null)
        {
            // Extract the messages for this page and push them to client side
            HttpContext.Current.Response.Write("<script>alert('" + pageTable[page].Dequeue() + "');</script>");
        }
    }
}


//Pokemon exception handling
           // MessageBox.Show("Exception has occured: " + //ex.Message);



Sunday, 2 December 2012

asp.net payment Getways code

online payment getway in asp.net / vb.net

https://support.ebs.in/app/index.php?/Knowledgebase/List/Index/9


click on Integration Kits--> then download according your project code files

Extratct Zip--> Run Page pay.aspx

fill all basic information

then respose url please copy paste url local host : 7856 any no those show on your Browser