Tuesday, November 29, 2011

Get Data From Store procedure parameter one by one by Come saparation

ALTER PROCEDURE [dbo].[SP_ORDER_INSERT] 
(
    @COMPANYID   INT,
 @CUSTOMERID   VARCHAR(50),
    @PRODUCTID   VARCHAR(100),
 @QUANTITY   INT,
 @PRICE    VARCHAR(200),
    @PRODUCTPRICE       VARCHAR(200),
-- @TOTALPRICE   DECIMAL(18,2),
 @TAX    DECIMAL(18,2),
 @SHIPPING   DECIMAL(18,2),
 @GRANDTOTAL   DECIMAL(18,2),
 @NOTES    NTEXT,
 @STATUS    VARCHAR(10),
 @ERRORMESSAGE       VARCHAR(MAX),
 @CREATEDBY   VARCHAR(50),
    @SHIPPINGCARRIER    VARCHAR(50),
 @TRACKINGNUMBER     VARCHAR(50),
 @PRODUCTCOLOR       VARCHAR(MAX),
 @PRODUCTSIZE        VARCHAR(MAX),
 @ORDERQTY           VARCHAR(MAX)
)
AS
BEGIN
 DECLARE @COUNTER AS INT
 DECLARE @PID  AS INT
 DECLARE @PRC  AS DECIMAL(18,2)
 DECLARE @PCOLOR     AS  VARCHAR(50)
 DECLARE @PSIZE      AS  VARCHAR(50)
 DECLARE @Pqty      AS   VARCHAR(20)
BEGIN TRY
 INSERT INTO [DBO].[ORDER]
           ( [COMPANYID],
    [CUSTOMERID],
    [QUANTITY],
    [PRICE],
    [TAX],
    [SHIPPING],
    [GRANDTOTAL],
    [NOTES],
    [CREATEDAT],
    [UPDATEDAT],
    [ErrorMessage],
    [STATUS],
    [SHIPPINGCARRIER],
    [TRACKINGNUMBER]
 
   )
    VALUES
           ( @COMPANYID,
    @CUSTOMERID,
    @QUANTITY,
    @PRICE,
    @TAX,
    @SHIPPING,
    @GRANDTOTAL,
    @NOTES,
       GETDATE(),
                '',  
    @ERRORMESSAGE,
    @STATUS,
    @SHIPPINGCARRIER,
                @TRACKINGNUMBER
           )
         
         
SELECT @COUNTER = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',0)------ this "FN_SPLIT_STRING" Function used      --------------------------------------------------------------------------------to count the number data separated by comma
 WHILE ( @COUNTER > 1) ---------------------------- While Loop Start
 BEGIN
  SET @COUNTER = @COUNTER - 1
  SELECT @PID = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',@COUNTER)--- Fetch --------------------------The  Data in @COUNTER Position in @PRODUCTID parameter
--  SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRICE,',',@COUNTER)
  SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRODUCTPRICE,',',@COUNTER)
  SELECT @PCOLOR = [dbo].[FN_SPLIT_STRING](@PRODUCTCOLOR,',',@COUNTER)
  SELECT @PSIZE = [dbo].[FN_SPLIT_STRING](@PRODUCTSIZE,',',@COUNTER)
        SELECT @Pqty    =   [dbo].[FN_SPLIT_STRING](@ORDERQTY,',',@COUNTER)
      
  INSERT INTO [DBO].[PRODUCTORDER]
      ( [ORDERID],
     [COMPANYID],
     [PRODUCTID],
     [QUANTITY],
     [PRODUCTPRICE],
     [ProductSize],
     [ProductColor],
     [CREATEDBY],
     [CREATEDAT],
     [UPDATEDBY],
     [UPDATEDAT]
    )
  VALUES
      ( IDENT_CURRENT('ORDER'),
     1,
     @PID,
     @Pqty,
     @PRC,
     @PSIZE,
     @PCOLOR,
     @CUSTOMERID,
     GETDATE(),
     '',
     ''
    )
 END

END TRY
BEGIN CATCH
END CATCH
BEGIN TRAN
 IF XACT_STATE() =0
 BEGIN
  COMMIT TRAN
 END
 ELSE
 BEGIN
 ROLLBACK TRAN
 END
END

Stored Procedure With While Loop

ALTER PROCEDURE [dbo].[sp_ORDER_INSERT]  
(
    @COMPANYID   INT,
 @CUSTOMERID   VARCHAR(50),
    @PRODUCTID   VARCHAR(100),
 @QUANTITY   INT,
 @PRICE    VARCHAR(200),
    @PRODUCTPRICE       VARCHAR(200),
-- @TOTALPRICE   DECIMAL(18,2),
 @TAX    DECIMAL(18,2),
 @SHIPPING   DECIMAL(18,2),
 @GRANDTOTAL   DECIMAL(18,2),
 @NOTES    NTEXT,
 @STATUS    VARCHAR(10),
 @ERRORMESSAGE       VARCHAR(MAX),
 @CREATEDBY   VARCHAR(50),
    @SHIPPINGCARRIER    VARCHAR(50),
 @TRACKINGNUMBER     VARCHAR(50),
 @PRODUCTCOLOR       VARCHAR(MAX),
 @PRODUCTSIZE        VARCHAR(MAX),
 @ORDERQTY           VARCHAR(MAX)
)
AS
BEGIN
 DECLARE @COUNTER AS INT
 DECLARE @PID  AS INT
 DECLARE @PRC  AS DECIMAL(18,2)
 DECLARE @PCOLOR     AS  VARCHAR(50)
 DECLARE @PSIZE      AS  VARCHAR(50)
 DECLARE @Pqty      AS   VARCHAR(20)
BEGIN TRY
 INSERT INTO [DBO].[ORDER]
           ( [COMPANYID],
    [CUSTOMERID],
    [QUANTITY],
    [PRICE],
    [TAX],
    [SHIPPING],
    [GRANDTOTAL],
    [NOTES],
    [CREATEDAT],
    [UPDATEDAT],
    [ErrorMessage],
    [STATUS],
    [SHIPPINGCARRIER],
    [TRACKINGNUMBER]
  
   )
    VALUES
           ( @COMPANYID,
    @CUSTOMERID,
    @QUANTITY,
    @PRICE,
    @TAX,
    @SHIPPING,
    @GRANDTOTAL,
    @NOTES,
       GETDATE(),
                '',   
    @ERRORMESSAGE,
    @STATUS,
    @SHIPPINGCARRIER,
                @TRACKINGNUMBER
           )
          
          
SELECT @COUNTER = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',0)------ this "FN_SPLIT_STRING" Function used      --------------------------------------------------------------------------------to count the number data separated by comma
 WHILE ( @COUNTER > 1) ---------------------------- While Loop Start
 BEGIN
  SET @COUNTER = @COUNTER - 1
  SELECT @PID = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',@COUNTER)--- Fetch --------------------------The  Data in @COUNTER Position in @PRODUCTID parameter
--  SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRICE,',',@COUNTER)
  SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRODUCTPRICE,',',@COUNTER)
  SELECT @PCOLOR = [dbo].[FN_SPLIT_STRING](@PRODUCTCOLOR,',',@COUNTER)
  SELECT @PSIZE = [dbo].[FN_SPLIT_STRING](@PRODUCTSIZE,',',@COUNTER)
        SELECT @Pqty    =   [dbo].[FN_SPLIT_STRING](@ORDERQTY,',',@COUNTER)
       
  INSERT INTO [DBO].[PRODUCTORDER]
      ( [ORDERID],
     [COMPANYID],
     [PRODUCTID],
     [QUANTITY],
     [PRODUCTPRICE],
     [ProductSize],
     [ProductColor],
     [CREATEDBY],
     [CREATEDAT],
     [UPDATEDBY],
     [UPDATEDAT]
    )
  VALUES
      ( IDENT_CURRENT('ORDER'),
     1,
     @PID,
     @Pqty,
     @PRC,
     @PSIZE,
     @PCOLOR,
     @CUSTOMERID,
     GETDATE(),
     '',
     ''
    )
 END

END TRY
BEGIN CATCH
END CATCH
BEGIN TRAN
 IF XACT_STATE() =0
 BEGIN
  COMMIT TRAN
 END
 ELSE
 BEGIN
 ROLLBACK TRAN
 END
END

Saturday, September 24, 2011

How to Validate Number With Validation Control

Validate number, Validate Number with asp.net validation control, Validate numaric value <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtBids" Display="Dynamic" ValidationExpression="^\d+$" ValidationGroup="step1" runat="server"  ErrorMessage="*">

Bid Should Be A Number

</asp:RegularExpressionValidator>

How To Validate Decimal Number With Validation Control

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="*" Display="Dynamic" ValidationGroup="step1" ControlToValidate="txtdiscount" ValidationExpression="^\d+(\.\d{1,2})?$" >
                                             Number Should Be Decimal
</asp:RegularExpressionValidator>

Saturday, August 13, 2011

Solution Page Validation error with "EnableEventValidation=true" Command




Add the below line if grid bind in page load  :--
if (!Page.IsPostBack)
{
DataTable  dt=methodName_that_fill_datatable();
}

add
<%@ Page AutoEventWireup="true" >

and remove<%@ Page EnableEventValidation="true" >

Thursday, August 11, 2011

How to convert Null value of database to some value

If you need to change null value of database at the time of  fetching data from database
then use this method ISNULL
SELECT  ISNull(ColumnName,'Your Converted Value ')  FROM TABLENAME


Thursday, July 21, 2011

how to turn off resize text area

<textarea id="txtMessageBox" runat="server" cols="20" rows="2"  style="width:400px;height:130px;resize: none;"></textarea>

Add High Lighted  line in style of textarea

Thursday, July 7, 2011

Page Redirection Using Meta Tag

Add this line at the top of meta tag .
<html>
<head>
<meta http-equiv="refresh" content="0; url=/index.aspx">
</head>

Wednesday, June 1, 2011

dropdown Bind or Add items in DropDownList with array and also add value and text saperately

 for (int count = 0; count < ds.Tables[0].Rows.Count; count++)
                                {
                                    strBrandname += ";" + Convert.ToString(ds.Tables[0].Rows[count]["BRANDNAME"]);
                                    strBrandid += ";" + Convert.ToString(ds.Tables[0].Rows[count]["BRANDID"]);
                                }
                                strBrandname = strBrandname.TrimStart(';');
                                strBrandid = strBrandid.TrimStart(';');
                                strTotalBrand = strBrandname + "-" + strBrandid;

                                string[] brand = Regex.Split(strBrandname, ";");
                                string[] BrandID = Regex.Split(strBrandid, ";");
                                DrpBrand.DataSource = "";
                                DrpBrand.DataBind();
                                for (int i = 0; i < brand.Length; i++)
                                {
                                    DrpBrand.Items.Add(new ListItem(brand[i],BrandID[i]));
                                }
                               

Friday, May 27, 2011

How Select a perticular list item of a dropdownList

if (drpEMailListName.Items.FindByValue(Convert.ToString(dsData.Tables[0].Rows[0]["EmailListID"])) != null)
                    { drpEMailListName.Items.FindByValue(Convert.ToString(dsData.Tables[0].Rows[0]["EmailListID"])).Selected = true; }

Thursday, May 26, 2011

Check drop down list is that value is present or not in list in c#

if (ddlUserType.Items.FindByValue("someValue") != null)   
{    
ddlUserType.SelectedValue = "someValue";     
}  

Saturday, May 21, 2011

How User control can call with out Register in ASPX page

if you add or call user control in web configuration

<configuration>
<system.web>
<pages><control>
<add src="../App_Controls/Admin.ascx" tagname="Header" tagprefix="Osnadmin">
<add src="../App_Controls/AdminLogin.ascx" tagname="LoginHeader" tagprefix="Osnadmin">
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.UI" tagprefix="asp">
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.UI.WebControls" tagprefix="asp">


</add></add></add></add></control>
</pages>
</system.web>
</configuration></div>














How to set an icon in a web site

 <head id="Head1" runat="server">
    <title>NeedNexus</title>
    <link href="../CSS/ie8-and-up.css" rel="stylesheet" type="text/css" media="all" />
    <link href="../CSS/style.css" rel="Stylesheet" type="text/css" media="all" />
    <link href="../CSS/main.css" rel="Stylesheet" type="text/css" media="all" />
    <link type="text/css" href="../CSS/jquery.mcdropdown.css" rel="stylesheet" media="all" />
    <link href="../fav_icon_1.png" rel="shortcut icon" />
    <link href="../neednexus_icon.ico" rel="shortcut icon" />

</head>

../ - means the main folder
Before you follow this just remove "!" from all tag
If this code help you please visit again . thank you for visit.

Tuesday, April 19, 2011

PopUp In Javascript

function Termspopup()
{
window.open("../Terms.aspx","mywindow", "menubar=0,location=1,status=1,scrollbars=1,resizable=0,width=400,height=500");
}

Java Script In .cs file

protected void linkbtnTerms_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Confirm", "Termspopup();", true);
}

On Mouse Over In Asp.net Text box





Tuesday, March 22, 2011

Download Crystal report for VS .Net 4.0

http://www.enterupload.com/sf60a8p3rmjm/CRforVS_13_0.exe.html
then click Regular Download ( > ) button.
then click Generate Download Link ( > ) button.
then wait few sec.
then download windows will come . and save download file.

Monday, March 14, 2011

To Run Crystal report in .net 4

To Run Crystal report in .net 4 Chang app config or web.config

with adding this code block









Friday, March 4, 2011

Conditional Message Box ( Yes, No) Button Click

DialogResult dlgResult = MessageBox.Show("Size Added . Do You Want To Entry the Stock ?", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{

}
else if (dlgResult == DialogResult.No)
{

}

Wednesday, March 2, 2011

How To Create a DLL Form a C# Class

Go to Start > Visual Studio Command Prompt > Type F: and press enter
and ten type the path of your Classfile which You want to convert as DLL file.

E.G

F:\WebSite1>csc /t:library class1.cs

Explanation 1) csc --------- is a compilation command.
2) /t:library -- is a command to convert a class file to dll.
3) class.cs ---- is the file name or class name.

Saturday, January 22, 2011

Mail Sending Code in C#


protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage msg1 = new MailMessage();

        msg1.To = "kunalchakraborty@gmail.com";
        msg1.From = "info@sncindia.org";
        msg1.Subject = "mailchk";
        msg1.BodyFormat = MailFormat.Text;
        msg1.Body = "Dear Sir,";
        SmtpMail.SmtpServer = "127.0.0.1";
        SmtpMail.Send(msg1);
    }

Thursday, January 13, 2011

Set dorpdown list 0 index position-------- "Select"----------

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ToString());
  protected void Page_Load(object sender, EventArgs e)
  {
      con.Open();
      string query = "select * from FilterGridViewBySection ";
      SqlCommand cmd = new SqlCommand(query, con);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds);
      DropDownList1.DataSource = ds;
      DropDownList1.DataTextField = "bid";
      DropDownList1.DataBind();
      //this line create a new item and set it at 0 index position
      DropDownList1.Items.Insert(0, new ListItem("Select", "select"));

  }

dynaic html in main page and also in same page using method using HTML generic Control

 private void getTopSolutions()
    {
        ContentPlaceHolder mpContentPlaceHolder;

        mpContentPlaceHolder =
          (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
        string query;

        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
      
        if (BlogType == "NULL")
        {
             query = "select top 6 * from blog order by bid";
        }
        else
        {
            query = "select top 6 * from blog where type='" + BlogType + "' order by bid";
        }
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            int iii = i + 1;
            HtmlGenericControl dv = (HtmlGenericControl)mpContentPlaceHolder.FindControl("newsdiv" + iii);
            dv.InnerText = ds.Tables[0].Rows[i]["header"].ToString();
        }

        ////newsdiv1.InnerText = "1 )" + ds.Tables[0].Rows[0]["header"].ToString();
        ////newsdiv2.InnerText = "2 )" + ds.Tables[0].Rows[1]["header"].ToString();
        ////newsdiv3.InnerText = "3 )" + ds.Tables[0].Rows[2]["header"].ToString();
        ////newsdiv4.InnerText = "4 )" + ds.Tables[0].Rows[3]["header"].ToString();
        ////newsdiv5.InnerText = "5 )" + ds.Tables[0].Rows[4]["header"].ToString();
        ////newsdiv6.InnerText = "6 )" + ds.Tables[0].Rows[5]["header"].ToString();

    }

    private void getretedSolutions()
    {
        string query;

        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();

        if (BlogType == "NULL")
        {
            query = "select top 6 * from blog order by bid";
        }
        else
        {
            query = "select top 6 * from blog where type='" + BlogType + "' order by bid";
        }
        SqlCommand cmd = new SqlCommand(query, con);
        SqlDataReader da = cmd.ExecuteReader();

    
      while (da.Read())
        {
            HtmlGenericControl dv = new HtmlGenericControl("div");
            dv.Attributes.Add("class", "cs_article");

            HtmlGenericControl h2 = new HtmlGenericControl("h2");

            HtmlAnchor a1 = new HtmlAnchor();
            a1.InnerText = da["header"].ToString();
            a1.HRef = "Solution.aspx?TopicId=" + da["bid"].ToString();
            h2.Controls.Add(a1);

            HtmlGenericControl p = new HtmlGenericControl("p");
            p.InnerText = da["matter"].ToString();


            HtmlAnchor a11 = new HtmlAnchor();
            a11.InnerText = "read more";
            a11.HRef = "Solution.aspx?TopicId=" + da["bid"].ToString();
        

            dv.Controls.Add(h2);
            dv.Controls.Add(p);
            dv.Controls.Add(a11);
            bddv.Controls.Add(dv);

Monday, January 10, 2011

dynanic formview

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class _Default : System.Web.UI.Page
{
    Class1 c = new Class1();
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {

            string sid = Request.QueryString[""].ToString();
            string type = Request.QueryString[""].ToString();

            SqlConnection cn = new SqlConnection(c.connectionString);
            SqlCommand cmd = new SqlCommand("dbo.usp_get_blog_info", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@sid", sid);
            cmd.Parameters.AddWithValue("@type", type);
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            da.Fill(ds);
        }
        catch
        {
            SqlConnection cn = new SqlConnection(c.connectionString);
            SqlCommand cmd = new SqlCommand("dbo.usp_get_blog_info", cn);
            cmd.CommandType = CommandType.StoredProcedure;
           //cmd.Parameters.Add(new SqlParameter("@sid","10000"));
          // cmd.Parameters.Add(new SqlParameter("type", "NULL"));
           cmd.Parameters.AddWithValue("@sid", "100000");
           cmd.Parameters.AddWithValue("@type", "NULL");
           SqlDataAdapter da = new SqlDataAdapter(cmd);
          
            da.Fill(ds);
            FormView1.DataSource = ds;
            FormView1.DataBind();
         Label l=(Label)FormView1.FindControl("Header");
           l.Text =ds.Tables[0].Rows[0]["header"].ToString();
             TextBox l1=(TextBox)FormView1.FindControl("Label1");
           l1.Text =ds.Tables[0].Rows[0]["matter"].ToString();
              
        }


    }

    protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {
        FormView1.PageIndex = e.NewPageIndex;
        int i = e.NewPageIndex;
        SqlConnection cn = new SqlConnection(c.connectionString);
        SqlCommand cmd = new SqlCommand("dbo.usp_get_blog_info", cn);
        cmd.CommandType = CommandType.StoredProcedure;
        //cmd.Parameters.Add(new SqlParameter("@sid","10000"));
        // cmd.Parameters.Add(new SqlParameter("type", "NULL"));
        cmd.Parameters.AddWithValue("@sid", "100000");
        cmd.Parameters.AddWithValue("@type", "NULL");
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds1 = new DataSet();
        da.Fill(ds1);
        FormView1.DataSource = ds;
        FormView1.DataBind();
//this new lable l initialize the header label in formview;

        Label l = (Label)FormView1.FindControl("Header");
        l.Text = ds1.Tables[0].Rows[i]["header"].ToString();
        TextBox l1 = (TextBox)FormView1.FindControl("Label1");
        l1.Text = ds1.Tables[0].Rows[i]["matter"].ToString();
        //FormView1.DataBind();
    }
    protected void Label1_TextChanged(object sender, EventArgs e)
    {

    }
 
          
          
          
          
          
          
          
          
          
          
          
          
          
                                                                                                                                                                                                              
      



        
    }

Sunday, January 9, 2011

Formview PageIndexChanging event c# coding

protected void fv1_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
fv1.PageIndex = e.NewPageIndex;
fv1.DataBind();
}

SQL Optimization

  SQL Optimization  1. Add where on your query  2. If you remove some data after the data return then remove the remove condition in the sel...