Tuesday, 24 December 2019

How to Delete duplicate rows from table in sql


How to Delete duplicate rows from table in sql server

WITH cte AS (
    SELECT 
Barcode,
        ROW_NUMBER() OVER (
            PARTITION BY 
                Barcode
            ORDER BY 
               Barcode
        ) row_num
     FROM 
        Isuued_Product_DetailsLog
)
DELETE FROM cte
WHERE row_num > 1;


I hope this will help to you

Saturday, 14 December 2019

how to use if else condition in sqlserver



How to use if else in sqlserver

This is my code  you can see below:
I hope this will help full to you

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[CCISales_Groupwise]

@From varchar(50),
@To varchar(50),
@Exid varchar(50),
@ExName varchar(50)
as
begin
if @Exid!='All'
Begin
select distinct  cdp.Exhibition_Id,cdp.Exhibition_Name, convert(Varchar(50),cdp.Added_On,103) AS dates,CDP.GroupMode,
(SELECT SUM(Product_Total) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103) and Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
)AS PRODUCT,(SELECT COUNT(*) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103) and Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
)AS Qty  from CCISold_Product_Details AS CDP where Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
group by Exhibition_Id, Exhibition_Name,convert(Varchar(50),cdp.Added_On,103),CDP.GroupMode
End
Else
begin
select distinct 
 convert(Varchar(50),cdp.Added_On,103) AS dates,CDP.GroupMode,
(SELECT SUM(Product_Total) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103) and Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
)AS PRODUCT,(SELECT COUNT(*) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103) and Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
)AS Qty  from CCISold_Product_Details AS CDP where Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
group by convert(Varchar(50),cdp.Added_On,103),CDP.GroupMode
end
--select distinct @From as frd,@To as Tod, cdp.Exhibition_Id,cdp.Exhibition_Name, convert(Varchar(50),cdp.Added_On,103) AS dates,CDP.GroupMode,
--(SELECT SUM(Product_Total) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103)
--)AS PRODUCT,(SELECT COUNT(*) FROM CCISold_Product_Details WHERE GROUPMODE=CDP.GROUPMODE and convert(Varchar(50),Added_On,103)=convert(Varchar(50),cdp.Added_On,103)
--)AS Qty  from CCISold_Product_Details AS CDP where Exhibition_Id like case when @Exid='All' then '%%' else '%'+@Exid end and Exhibition_Name like case when @ExName='All' then '%%' else '%'+@ExName end
--group by Exhibition_Id, Exhibition_Name,convert(Varchar(50),cdp.Added_On,103),CDP.GroupMode
end

Thursday, 12 December 2019

How to create a comma delimited list using SELECT clause from table column?

How to create a comma delimited list using SELECT clause from table column?




USE AdventureWorks
GO
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Name
FROM Production.Product
SELECT @listStr
GO

I hope this will helpful to you

Sunday, 1 December 2019

How to get month from a date in sqlserver

How to get month from a date in  SQL server



If  I am writing select Month(getdate()) then I am getting from month.But if I am writing this command like

Select Month('02/12/2019') then it give me month=2
but here my month is 12 what I can do

Kindly help
thanks in advance

Saturday, 30 November 2019

How to delete file from folder in asp.net

How to delete any file form the folder



protected void btnDelete_Click(object sender, EventArgs e)
{
      
string file_name = yourfilename;
      
string path = Server.MapPath("files//" + file_name);
      
FileInfo file = new FileInfo(path);
      
if (file.Exists)//check file exsit or not      {
           file.Delete();
           lbl_output.Text = file_name + 
" file deleted successfully";
           lbl_output.ForeColor = 
Color.Green;
      }
      
else      {
           lbl_output.Text = file_name + 
" This file does not exists ";
           lbl_output.ForeColor = 
Color.Red;
      }
}
 I hope this will help you

Friday, 29 November 2019

How to get month,day and year from birth date

How to get month,day and year from birth date


Use this

   string birthDate = "2015/02/01";
   var split = birthDate.Split('/');
    If you get birthDate from database as datetime, you can extract date parts from it like:

    DateTime birthDate = DateTime.Now.Date;

    var year = birthDate.Year;
    var month = birthDate.Month;
    var day = birthDate.Day;

I hope this may help you

Wednesday, 27 November 2019

How to create setup in asp C#

How to create setup in asp C#



Use Visual Studio Setup project. Setup project can automatically include .NET framework setup in your installation package:
Here is my step-by-step for windows forms application:
  1. Create setup project. You can use Setup Wizard.
    enter image description here
  2. Select project type.
    enter image description here
  3. Select output.
    enter image description here
  4. Hit Finish.
  5. Open setup project properties.
    enter image description here
  6. Chose to include .NET framework.
    enter image description here
  7. Build setup project
  8. Check output
    enter image description here

Note: The Visual Studio Installer projects are no longer pre-packed with Visual Studio. However, in Visual Studio 2013 you can download them by using:
Tools > Extensions and Updates > Online (search) > Visual Studio Installer Projects

Thursday, 21 November 2019

Database Attaching Error in sql


Database Attaching Error in sql

CREATE
 DATABASE MyAdventureWorks  

    ON (FILENAME = 'D:\WINDB\PIANONEW.mdf'),   This is my .mdf  file path
    (FILENAME = 'D:\WINDB\PIANONEW.ldf')   This is my .ldf  file path
    FOR ATTACH; 


If  You are getting error on .ldf then remove .ldf from above code
this will help you

Maximum report processing jobs limit

Maximum report processing jobs limit


Use Below method this will help you

ReportDocument crystalReport = new ReportDocument();
 
protected void Page_Unload(object sender, EventArgs e)
    {
        crystalReport.Close();
        crystalReport.Dispose();
    }

On each load you have to dispose your crystal session

Wednesday, 13 November 2019

Need sample Birthday Calendar.(ASP.NET using C#)

Need sample Birthday Calendar.(ASP.NET using C#)


      We below given link it may help you

      http://www.beansoftware.com/ASP.NET-Tutorials/Calendar-Web-Application.aspx

Tuesday, 12 November 2019

Call JavaScript function (in aspx) on aspx.cs using a button

Call JavaScript function (in aspx) on aspx.cs using a button


I have you this but this is not working 
protected void button_Click(object sender , EventArgs e)
{
        string jsMethodName= = "NewPage()";
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "uniqueKey", jsMethodName, true);

      //or
      //ScriptManager.RegisterStartupScript(this, GetType(), "NewPage()", false); 
}
Actually I want to open popup modal


Kindly Help 
Thanks In Advance

modify the data type of the column from INT to VARCHAR:

 Modify the data type of the column from INT to VARCHAR:



You have to use alter command see below:

ALTER TABLE Mytablename ALTER COLUMN tablecolumn VARCHAR (2);

Friday, 8 November 2019

The IListSource does not contain any data sources.

The IListSource does not contain any data sources.


If you are getting error on this that mean you don't have written this statement see below

sda.Fill(ds);

use this

  SqlCommand cmd = new SqlCommand("Select * from Student_Master", con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            Repeater1.DataSource = ds;
            Repeater1.DataBind();

The IListSource does not contain any data sources.

The IListSource does not contain any data sources.


why I am getting error when bind repeater control of asp

need a help
thanks in advance

Dynamically Bind Repeater Control In ASP.NET From


Dynamically Bind Repeater Control In ASP.NET 

See below

 <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <table class="table table-bordered">
                        <tr>
                            <td style="width: 20%;">
                                <img alt="" width="150" class="img-thumbnail" src='<%#Eval("Profile_Picture")%>' />
                            </td>
                       
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:Repeater>

 private void BindRepeator()
    {
        con.Open();
        try
        {

            SqlCommand cmd = new SqlCommand("Select * from Student_Master", con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            Repeater1.DataSource = ds;
            Repeater1.DataBind();
        }
        catch (SqlException)
        {

        }
        finally
        {
            con.Close();
        }
     
    }
This will help you

RowDataBound Event In GridView In ASP.NET



RowDataBound Event In GridView In ASP.NET


  1. <form id="form1" runat="server">  
  2.     <div>  
  3.         <asp:GridView ID="GridView1" runat="server" CellPadding="6" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">  
  4.             <Columns>  
  5.                 <asp:BoundField DataField="Id" HeaderText="Id"/>  
  6.                 <asp:BoundField DataField="Name" HeaderText="Name"/>  
  7.                 <asp:BoundField DataField="City" HeaderText="City"/>  
  8.                 <asp:BoundField DataField="Salary" HeaderText="Salary"/>  
  9.             </Columns>  
  10.         </asp:GridView>  
  11.     </div>  
  12. </form>  


  1.  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.     {  
  3.         //Checking the RowType of the Row  
  4.         if(e.Row.RowType==DataControlRowType.DataRow)  
  5.         {  
  6.             //If Salary is less than 10000 than set the row Background Color to Cyan  
  7.             if(Convert.ToInt32(e.Row.Cells[3].Text)<10000)  
  8.             {  
  9.                 e.Row.BackColor = Color.Cyan;  
  10.             }  
  11.         }  
  12.     }