Wednesday, 22 May 2013

How to revese number | integer in c# | examples code | comments

How to revese number | integer in c# | examples code | comments
In this article we are going to learn how to reverse a integer or numeric number in c#.
With help of for loop i have shown the program to reverse the given number.
Don't ignore comments.

        int temp = 0;  //took temporary variable
        int val =13298765; //passed  integer value to the integer type variable val
        for (int i=0; val>0 ;i++) // now  increment of i
        {
            temp =val % 10; // storing all the   single digit  in temp variable
            val =val/10; //taking remaining value after mod
            Response.Write(temp);
        }


In this program we don't need to take length because it won't works.
it works at time of sring and array.
mod [%] will give you last value on number.
and / will store remaining one in val variable.




output :-56789231



another example
 /int count = 34;
        int temp = 0;
        while (count > 0)
        {
            temp = count % 10;
            count = count / 10;
         Response.Write(temp);



     

How to reverse string in c# | asp.net | example | output

How to reverse string in c# | asp.net | example | output
reverse string using for loop in c#  with program source code.
         In this program we are going to learn how to reverse  a string using temporary variable and
        display them at last .a very simple process .take string calculate length of string using for loop
        count it till its last character.after display it .
        i have shown program with source code. and output also .


        string temp="";  //took temporary variable
        string str = "enteryourstring"; //passed string
        int last = str.Length; //calculated length of string
        for (int i =last -1;i>=0 ; i--) // now decrement
        {
            temp = temp + str[i]; // storing all the  character in temp variable
        }
        Response.Write(temp); //display

output:gnirtsruoyretne

Monday, 8 April 2013

gridview rowcommand with insert | update | delete in c#

gridview rowcommand with insert | update | delete in c#
In this article we will learn how to use grid view rowcommand event to insert, update and delete the record in asp.net with c#

now for that i have created table named as usertbl. and took three field first one is id , name and company.
same way three text box .to insert the value into table.
4    rajana    nit
38    dev    lolo
45    dev    lolol



using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Data.SqlClient;
using System.Web.UI.WebControls;



public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);


    protected void Page_Init(object sender, EventArgs e)
    {
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        display(); 

    }
    protected void btnsbmit_Click(object sender, EventArgs e) //for insertion
    {
        try
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("insert_db", con);
            cmd.CommandType = CommandType.StoredProcedure;
           
            cmd.Parameters.AddWithValue("@nm", txtnm.Text);
            cmd.Parameters.AddWithValue("@comp", txtcom .Text );
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
        catch { }

        finally
        {
            con.Close();
           
        }

        display();

    }
    protected void grd_RowCommand(object sender, GridViewCommandEventArgs e)
    {



        if (e.CommandName == "select")
        {

            ViewState["val"] = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = (GridViewRow)(((LinkButton  )e.CommandSource).NamingContainer);
//taking gridview index so we can that row values.
            int selIndex = row.RowIndex;
            string last = grd.Rows[selIndex].Cells[2].Text;
            string comp = grd.Rows[selIndex].Cells[3].Text;
            txtnm.Text = last;
            txtcom.Text = comp;
         
      }
        if (e.CommandName =="del")
        {
            int del = Convert.ToInt32(e.CommandArgument);
            ViewState["val"] = del;
           SqlCommand cmd = new SqlCommand("delete from usertbl where id='" + del + "'", con);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                lblmsg.Text = "Record deleted succesfully";
            }
            catch { }
            finally
            {
                con.Close();
            }

            display();

           
        }

    }
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        int i = 0;
        int last =Convert.ToInt32 ( ViewState["val"]);
        //string l1 = Replace(txtnm.Text, "", "-");
        string str = "update usertbl set name='" + txtnm .Text  + "', company ='" + txtcom .Text +"' where id='" + last + "'";
        con.Open();
        SqlCommand cndupdate = new SqlCommand(str, con);
        i=cndupdate.ExecuteNonQuery();
        if (i >= 1)
        {
            lblmsg.Text ="Record updated succesfully";
        }
        con.Close();
       
        display();

    }
    public  void  display()
    {
       
        DataSet ds = new DataSet();
        con.Open();
        SqlCommand cmd1 = new SqlCommand("select * from usertbl", con);
        SqlDataAdapter sda = new SqlDataAdapter(cmd1);
        sda.Fill(ds);
        ViewState["ds"] = ds;
        grd.DataSource = ds;
        grd.DataBind();
        con.Close();
    }

 
    protected void grd_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void grd_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataSet  ds = new DataSet ();
        ds=(DataSet )(ViewState["ds"]);
       // DataView dv = new DataView(ViewState ["ds"]);
       
    }
}





<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <table>
   <tr><td>
   <asp:Label runat="server" ID="lbl">name</asp:Label></td>
   <td><asp:TextBox runat="server" ID="txtnm"></asp:TextBox></td>
   </tr>
    <tr><td>
   <asp:Label runat="server" ID="Label1">Company</asp:Label></td>
   <td><asp:TextBox runat="server" ID="txtcom"></asp:TextBox></td>
   </tr>
  <tr><td><asp:Button runat="server" ID="btnsbmit" onclick="btnsbmit_Click"
          Text="Submit" /></td> <td>
      <asp:Button runat="server" ID="btnupdate"
          Text="update" onclick="btnupdate_Click" Visible="False" /><td></tr>
          <tr><td><asp:Label runat ="server" ID="lblmsg"></asp:Label></td></tr>
   </table>
   <asp:GridView ID="grd" runat="server" onrowcommand="grd_RowCommand"
            onsorting="grd_Sorting">
   <Columns >
  
   <asp:TemplateField HeaderText ="Edit"  >
   <ItemTemplate >
  
<asp:LinkButton ID="edit" CommandName ="select" runat ="server" Text ="Edit"  CommandArgument  ='<%# DataBinder.Eval(Container, "DataItem.id") %>' ></asp:LinkButton>
<asp:LinkButton ID="delete" CommandName ="del" runat ="server" Text ="delete"  CommandArgument ='<%#DataBinder.Eval(Container,"DataItem.id") %>'></asp:LinkButton>
  </ItemTemplate>
     </asp:TemplateField>
   </Columns>
   </asp:GridView>
  
    </div>
    </form>
</body>
</html>


name
Company



Editidnamecompany
Edit delete 4rajananit
Edit delete 38devlolo
Edit delete 45devlolol

Thursday, 4 April 2013

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory

It is an error to use a section registered as   allowDefinition='MachineToApplication' beyond application level.  This error can be caused   by a virtual directory

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.
E:\project\myproject\web.config 68


solution :-
If you are getting error like this and after  running your application you are getting error
liker <authentication mode="Forms"/> so  i have Solution just check your project or website
which you have opened . may be there will another web.config file.
where you have pasted your application or website folder open only than folder don't open
sub folder .


Example you  want to open your primenumberprogram website ,means  primenumberprogram  is
your website folder and there is web.config file , you kept your primenumberprogram   folder
in mywebsite folder and you are opening mywebsite folder instead of primenumberprogram  
folder then you will get erro like It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level.  This error can be caused
by a virtual directory not being configured as an application in IIS.

E:\project\myproject\web.config.

so check acccurately where you have kept your website and from where you are opening that folder.
hope it will work

Monday, 1 April 2013

Maximum request length exceeded. | asp.net | vb.net

Maximum request length exceeded. | asp.net | vb.net

i am designing crystal report , for single or less record its working proper ,
means it is displaying proper but at time of
displaying lacs record at a time its showing error

Maximum request length exceeded. 

so what i did , i just pasted one line code and its started working fine.
how to paste that code and where .
go into web.config file and search for <system.web>
 paste

<httpRuntime maxRequestLength="1000000" />
brfore closing system.web

<system.web>

other code ----------------
---------------------------
<httpRuntime maxRequestLength="1000000" />
</system.web>

i am sure it will work.

About maxRequestLength i think it will related something if we are posting  huge data to
server and it cause , so to avoid we provide  length='1000000'
The value must be inside the range 0-2097151.