Sample Stored procedure with Transaction and try Ctahc block

No comments:
Create procedure [dbo].[sp_insertsample]
(@Secondname varchar(50)=null,@Address varchar(50)=null,@Age int=null,
@name varchar(50)=null,@unitPrice varchar(50)=null,@soldprice int=null)

as
Begin

    Begin Try
       Begin transaction t1

Declare @Error varchar(max)=null
insert into tbl_test2(Name,Address,Age)values(@Secondname,@Address,@Age)
WAITFOR DELAY '00:00:10'
insert into tbl_test3(Name,[Unit Price],[Sold Price])values(@name,@unitPrice,@soldprice)
commit transaction t1
   End Try
    Begin Catch
         
                rollback transaction t1
                     select
                     ERROR_NUMBER() as ErrorNumber,
                     ERROR_MESSAGE() as ErrorMessage

          
    End Catch


End


How to Select one Row from Dataset in C# Asp.net

No comments:
protected void lnkbtnView_Click(object sender, System.EventArgs e)
    {
        DataTable dt = null;
        DataRow[] dr = null;
        LinkButton lnkbtn = (LinkButton)sender as LinkButton;
        //View State having the data
        if (ViewState["GetRecords"] != null)
        {
            dt = (DataTable)ViewState["GetRecords"];


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                // dr = dt.Select("Sno = '" + lnkbtn.CommandArgument + "'");
                if (dt.Rows[i]["Sno"].ToString() == lnkbtn.CommandArgument.ToString())
                {
                }
                else
                {
                    dt.Rows.Remove(dt.Rows[i]);
                    dt.AcceptChanges();
                    i--;
                }
            }
            detailsView.DataSource = dt;
            detailsView.DataBind();
            Bind();
        }


    }

how to get sum of the numbers in C# .net using Recursive Function

No comments:
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string newNumber = string.Empty;
        newNumber = CalculateRecords(txtNumber.Text).ToString();
        lblMessage.Text = newNumber.ToString();

    }
   
Mormal Method
     
    private int CalculateRecords(string test)
    {
        try
        {
            int y = 0;
            string calculatedText = string.Empty;
        Label:
            if (calculatedText != null && calculatedText != string.Empty)
            {
                test = calculatedText;
                y = 0;
            }
            string[] x = new string[test.Length];
            for (int i = 0; i < test.Length; i++)
            {
                x[i] = test.Substring(i, 1);
                y += int.Parse((x[i]));

            }
            string j = y.ToString();
            string[] z = new string[j.Length];
            if (z.Length > 1)
            {
                calculatedText = j;
                goto Label;
            }
            return y;
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

Input:"123456789"
Output:9


Recursive Function Method

Recursive Function is a Function that call itself.

private int CalculateRecords(string test)
    {
        try
        {
            int y = 0;
            if (test.Length > 1)
            {
                string[] x = new string[test.Length];
                for (int i = 0; i < test.Length; i++)
                {
                    x[i] = test.Substring(i, 1);
                    y += int.Parse((x[i]));
                }
                test = Convert.ToString(CalculateRecords(y.ToString()));
            }
            return Convert.ToInt32(test);
        }
        catch (Exception ex)
        {

            throw ex;
        }

    }

How to uncheck or deselect radiobutton list in asp.net using javascript.

No comments:
<form id="form1" runat="server">
        <div>
             <asp:RadioButtonList ID="re" runat="server" AutoPostBack="false" RepeatDirection="Horizontal" onclick="javascript:DeSelectAll()">
                <asp:ListItem Text="One" Value="1"></asp:ListItem>
                <asp:ListItem Text="Two" Value="2"></asp:ListItem>
                <asp:ListItem Text="Three" Value="3"></asp:ListItem>
            </asp:RadioButtonList>
            <asp:Label ID="lblmessage" runat="server"></asp:Label>

          


            <script type="text/javascript">
                var allRadios = document.getElementsByName('re');
                var booRadio;
                var x = 0;
                for (x = 0; x < allRadios.length; x++) {

                    allRadios[x].onclick = function () {
                        if (booRadio == this) {
                            this.checked = false;
                            booRadio = null;
                        } else {
                            booRadio = this;
                        }
                    };
                }
            </script>

        </div>

    </form>

How to use Chart in asp.net or Barchat example in asp.net

No comments:

Introduction:


In this example Iam Going to Explain  how to use Chart in asp.net(Frame work 4.0 onwards Chat availble in Data Section).




Description:When you want to display your data in graphical form, you can use Chart The Chart  can render an image that displays data in a variety of chart types. TheChart can render more than 30 types of charts, including all the types of charts that you might be familiar with from Microsoft Excel or other tools — area charts, bar charts, column charts, line charts, and pie charts, along with more specialized charts like stock charts.

Here iam giving Database table Design.


Year Jan Feb March April May
2014 10000 20000 1500 18000 20000
2015 3000 5000 7000 15000 10000

Here is Aspx Coding

<body>
    <form id="form1" runat="server">
        <div>
       


       <asp:Chart ID="Chart1" runat="server" BorderlineWidth="0" Width="550px">
        <Series>
        <asp:Series Name="Series1" XValueMember="Year" YValueMembers="Jan" LegendText="Jan"   IsValueShownAsLabel="false" ChartArea="ChartArea1" MarkerBorderColor="#DBDBDB"></asp:Series>

        <asp:Series Name="Series2" XValueMember="Year" YValueMembers="Feb" LegendText="Feb" IsValueShownAsLabel="false" ChartArea="ChartArea1" MarkerBorderColor="#DBDBDB"></asp:Series>

         <asp:Series Name="Series3" XValueMember="Year" YValueMembers="March" LegendText="March" IsValueShownAsLabel="false" ChartArea="ChartArea1" MarkerBorderColor="#DBDBDB"></asp:Series>

         <asp:Series Name="Series4" XValueMember="Year" YValueMembers="April" LegendText="April" IsValueShownAsLabel="false" ChartArea="ChartArea1" MarkerBorderColor="#DBDBDB"></asp:Series>

          <asp:Series Name="Series5" XValueMember="Year" YValueMembers="May" LegendText="May" IsValueShownAsLabel="false" ChartArea="ChartArea1" MarkerBorderColor="#DBDBDB"></asp:Series>
                
           </Series>
            <Legends>
            <asp:Legend Title="Month"></asp:Legend>
                </Legends>
                <Titles>
                    <asp:Title Docking="Bottom" Text="Percentage"></asp:Title>
                </Titles>
                <ChartAreas>
                    <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
                </ChartAreas>
            </asp:Chart>
        </div>
    </form>
</body>


Here Aspx.Cs coding

    SqlConnection con = new SqlConnection("Your Connection String");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
          
            FetchReportData();
        }
    }
    public void FetchReportData()
    {
        SqlCommand cmd = new SqlCommand("select * from Percentage",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
       
        Chart1.DataSource = ds;
        Chart1.DataBind();

    }