Random Posts

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Thursday, 31 May 2018

Dynamically Generate BarCode and Display Image in ASP.net

Step 1:
First of all you have to download BarCode Font and Install it.After Installing you have to restart the system.

Step2:
Create one webform and write the following code in .aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BarCodeGenerate.aspx.cs" Inherits="BarCodeGenerate" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
<asp:Button ID="btnGenerate" runat="server" Text="Generate" OnClick="btnGenerate_Click" />
<hr />
<asp:PlaceHolder ID="plBarCode" runat="server" />
    </div>
    </form>
</body>
</html>
Step3:
Import 3 name space as following:
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

Step 4:
Write the following code in button click event:
 protected void btnGenerate_Click(object sender, EventArgs e)
    {
        string barCode = txtCode.Text;
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font("IDAutomationHC39M", 16);
                PointF point = new PointF(2f, 2f);
                SolidBrush blackBrush = new SolidBrush(Color.Black);
                SolidBrush whiteBrush = new SolidBrush(Color.White);
                graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
                graphics.DrawString("*" + barCode + "*", oFont, blackBrush, point);
            }
            using (MemoryStream ms = new MemoryStream())
            {
                bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] byteImage = ms.ToArray();

                Convert.ToBase64String(byteImage);
                imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
            }
            plBarCode.Controls.Add(imgBarCode);
        }
}

Step 5:
After write the following code run the page and enter some number in the textbox and see the out put as following:



Saturday, 13 January 2018

CRUD Operation using classic ASP with SQL Server Database

1) Create a table following column:
   
create table Address(id int identity(100,1),name varchar(30),mobile char(10),address varchar(30),email varchar(30),country varchar(30),state varchar(30),city varchar(30),password varchar(30))

2)Create following storedProcedures:
sp_deleteaddress:
    create procedure sp_deleteaddress(@id int)
as
begin
delete from Address where id=@id
end

sp_insertaddress:

create procedure sp_insertaddress(@name varchar(30),@mobile char(14),@address varchar(40),@email varchar(50),@state varchar(30),@city varchar(40),@password varchar(40),@country varchar(30))
as
begin
insert into address (name,mobile,address,email,country,state,city,password) values(@name,@mobile,@address,@email,@country,@state,@city,@password)
end


3)Create A page with name "List.asp"  and write the following code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
      <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="Scripts/bootstrap.min.js"></script>
    <title></title>
    
    <h1>CRUD Operation using classic ASP</h1>
    <%

dim db_connection

db_connection = "Provider=SQLOLEDB;Data Source=manoj\sqlexpress;Database=classicasp;Integrated Security=SSPI;"


set conn = server.createobject("adodb.connection")
set Cmd = Server.CreateObject("ADODB.Command")

conn.open(db_connection)

set rs = Server.CreateObject("ADODB.RecordSet")
    
sql="select * from Address"
set rs = Conn.execute(sql)

'if (rs.bof and rs.eof) then
       'response.Write "<span class=""error"">No Record Found</span>"
       'response.End
'end if
    %>
</head>
<body>
    <div class="table-responsive">
    <table border="1" class="table">
        <tr>
            <td><strong>Edit</strong></td>
            <td><strong>Delete</strong></td>
            <td><strong>Name</strong></td>
            <td><strong>Mobile</strong></td>
            <td><strong>Email</strong></td>
            <td><strong>City</strong></td>
        </tr>
        <%
             
              while not rs.eof
        %>
        <tr>

            <td><a href="add.asp?Name=<%response.write(rs("Name"))%>"   class="btn btn-info" style="width:80px;"><%=rs("Name")%></a></td>
            <td><a href="Delete.asp?Id=<%=rs("Id")%>" >Delete</a>
            </td>
            <td><%=rs("Name")%></td>
            <td><%=rs("Mobile")%></td>
            <td><%=rs("Email")%></td>
            <td><%=rs("City")%></td>

        </tr>

        <%
              rs.movenext
              wend
        %>
    </table>
        </div>
   


   <strong> <a href="add.asp">NewMember</a></strong>

4). Create a Page with name "Add.asp" and write the following code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="Scripts/bootstrap.min.js"></script>
    
    <script src="Scripts/jquery-3.2.1.min.js"></script>
    <title></title>
    <script>
        $(document).ready(function(){
         $("#namerror").hide();
        var nameerror = false;
         $("#Name").focusout(function () {
                check_username();
            });
         function check_username() {
                var unamelength = $("#Name").val().length;
                if(unamelength<5||unamelength>20)
                {
                    $("#nameerror").html("username should be between 5 to 20 character");
                    $("#nameerror").show();
                    usernameerror = true;
                }
                else
                {
                    $("#nameerror").hide();
                }
            }
        

        });
    </script>
    
    
  

    <%

dim db_connection

db_connection = "Provider=SQLOLEDB;Data Source=manoj\sqlexpress;Database=classicasp;Integrated Security=SSPI;"


set conn = server.createobject("adodb.connection")
set Cmd = Server.CreateObject("ADODB.Command")
'-------------------------------------------------------
conn.open (db_connection)
'-------------------------------------------------------
set rs = Server.CreateObject("ADODB.RecordSet")
%>

<%
Name = request.QueryString("Name")
    if Name <> "" then
       sSQL = "SELECT  * FROM Address where Name = '" & Name & "'"
       'response.Write sSQL
       set rs = Conn.execute(sSQL)
      
       if not(rs.bof and rs.eof) then
              Mobile = rs("Mobile")
              Email = rs("Email")
              Country =rs("Country")    
              State = rs("State")
              City = rs("City")
              Password = rs("Password")
        Address = rs("Address")
    Id=rs("Id")
       end if
end if

    %>
  
   
     </head>
<body>
   
    <form action="posting.asp" name="frm_config" id="frm_config" method="post">
        <center>
            <div id="diiv1" style="background-color:aquamarine;color:red;font-family:Arial, Helvetica, sans-serif;width:350px;">Registration Form</div>
            <fieldset style="border:double;align-content:center;width:350px;background-color:azure;">
    <table>
        <tr>
            <td>
                Name
            </td>
            <td>
                <% if Id <> "" then %><input type="hidden" name="Id" id="Id" value="<%=Id%>" /><% end if %>
           <input type="text" id="Name" name="Name"   value="<%=Name%>" class="form-control" style="width:200px;" /></td>
           
        </tr>
         <tr>
            <td>
                Mobile
            </td>
            <td><input type="text" id="Text1" name="Mobile" maxlength="10" value="<%=Mobile%>"  class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
                Email
            </td>
            <td><input type="text" id="Text2" name="Email" value="<%=Email%>"  class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
                Country
            </td>
            <td><input type="text" id="Text3" name="Country" value="<%=Country%>" class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
                State
            </td>
            <td><input type="text" id="Text4" name="State" value="<%=State%>" class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
               City
            </td>
            <td><input type="text" id="Text5" name="City" value="<%=City%>"  class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
                Password
            </td>
            <td><input type="password" id="Text6" name="Password" value="<%=Password%>"  class="form-control" style="width:200px;" /></td>
        </tr>
         <tr>
            <td>
                Address
            </td>
            <td><input type="text" id="Text7" name="Address" value="<%=Address%>"  class="form-control" style="width:200px;" /></td>
        </tr>
       
        <tr>
         
            <td colspan="2" align="center">
                <input type="submit" id="btnsubmit" value="Submit" class="btn btn-primary" style="width:200px;"/><div id="post_result"></div>
            </td>
           
        </tr>
    </table>
                </fieldset>
            </center>

        </form>
  
</body>
  

</html>

5).Create a page with name "Posting.asp" and write the follwing code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <%

dim db_connection

db_connection = "Provider=SQLOLEDB;Data Source=manoj\sqlexpress;Database=classicasp;Integrated Security=SSPI;"


set conn = server.createobject("adodb.connection")
set Cmd = Server.CreateObject("ADODB.Command")
'-------------------------------------------------------
conn.open (db_connection)
'-------------------------------------------------------
set rs = Server.CreateObject("ADODB.RecordSet")
%>
    <%
Name = request.form("Name")
Mobile = request.form("Mobile")
Email= request.form("Email")
Address = request.form("Address")
Country = request.form("Country")
State= request.form("State")
City = request.form("City")
Password = request.form("Password")
  Id=request.Form("Id")

        if(Id>0) then
    
        sSQL="Update Address SET Mobile='" &Mobile& "',Email='" &Email& "', Country='" & Country & "',State='" & State & "',City='" & City & "',Password='" & Password & "',Address='" & Address& "'where Id='" & Id & "'"
       
        else
     sSQL= "Exec sp_insertaddress"

end if
        conn.execute(sSQL)
       response.Redirect("list.asp")
%>
</body>
   
</html>

6).Create a page with name "Delete.asp" and write the following code:
<%

dim db_connection

db_connection = "Provider=SQLOLEDB;Data Source=manoj\sqlexpress;Database=classicasp;Integrated Security=SSPI;"


set conn = server.createobject("adodb.connection")
set Cmd = Server.CreateObject("ADODB.Command")
'-------------------------------------------------------
conn.open (db_connection)
'-------------------------------------------------------
set rs = Server.CreateObject("ADODB.RecordSet")
%>
    <% 
        Id=request.QueryString("Id")
        if(Id>0) then
        sSQL="Exec sp_deleteaddress "&request.QueryString("Id")&""
     
        conn.execute(sSQL)
         response.Redirect("List.asp")
        end if
 %>


Friday, 29 December 2017

Fetching data from Database server using jQuer ajax in asp.net

step 1: Create Following two tables in sql Server:

CREATE TABLE DEPT1(DEPTID INT IDENTITY(1,1) primary key,DEPTNAME VARCHAR(30))

CREATE TABLE EMP1(EMPID INT IDENTITY(101,1),EMPNAME VARCHAR(30),EMPJOB VARCHAR(30),EMPSAL MONEY, deptid int  foreign key references dept1(deptid) )

Step 2: Create a web page named it as("eg1.aspx") and write the following codes:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jQuery-3.2.1.min.js"></script>
    <script>
        $(document).ready(function () {
           
            function loadData() {
                var deptid = $("#ddldept option:selected").val();
                $.ajax({
                    type: "POST",
                    url: "ViewEmp.aspx",
                    data:{"deptid":deptid},
                    datatple: "html",
                    success: function (data) {
                        $("#panel1").html(data);
                    },
                    error: function (error) { alert("Loading Failed") }

                });
            }
            loadData();
            $("#ddldept").change(function () {
                loadData();
            });
        });
    </script>
   
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
        <b>Deptname:</b>
        <asp:DropDownList ID="ddldept" runat="server" />
        <br />
        <asp:Panel ID="panel1" runat="server" ></asp:Panel>
   
    </div>
    </form>
   
</body>

</html>

Step 3:  Write the following code in code behind file:
              using System.Data;
              using System.Data.SqlClient;
             public partial class eg1 : System.Web.UI.Page
{
    SqlConnection con = null;
    SqlDataReader dr = null;
    SqlDataAdapter da = null;
    DataSet ds = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("Data Source=MANOJ\\SQLEXPRESS;Database=quiz;Integrated Security=SSPI");
        if(!IsPostBack)
        {
            bindddl();
        }
    }
    private void bindddl()
    {
        string sqlquery = "select *from dept1";
        da = new SqlDataAdapter(sqlquery, con);
        ds = new DataSet();
        da.Fill(ds,"dept1");
        ddldept.DataSource = ds.Tables["dept1"];
        ddldept.DataTextField = "deptname";
        ddldept.DataValueField = "deptid";
        ddldept.DataBind();
        ddldept.Items.Insert(0,new ListItem( "---Select Department---","0"));
       

    }
}

Step 4: Create another web page name it as("ViewEmp.aspx") and write the following code:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="gview1" runat="server" Width="100%" Caption="Employee Data" EmptyDataText="No Employee Data Available for this selected dept" EmptyDataRowStyle-ForeColor="Red" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
        <AlternatingRowStyle BackColor="#F7F7F7" />
<EmptyDataRowStyle ForeColor="Red"></EmptyDataRowStyle>
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <SortedAscendingCellStyle BackColor="#F4F4FD" />
        <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
        <SortedDescendingCellStyle BackColor="#D8D8F0" />
        <SortedDescendingHeaderStyle BackColor="#3E3277" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Step 5:Write the following code in code behind file in("ViewEmp.aspx.cs")
using System.Data;
using System.Data.SqlClient;


public partial class ViewEmp : System.Web.UI.Page
{
    SqlConnection con = null;
    SqlDataAdapter da = null;
    DataSet ds = null;
    string sqlquery = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["deptid"] == null)
            Response.Redirect("eg1.aspx");
        con = new SqlConnection("Data Source=MANOJ\\SQLEXPRESS;Database=quiz;Integrated Security=SSPI");
        BindEmpData();

    }
    private void BindEmpData()
    {
        int deptid = int.Parse(Request.Form["deptid"].ToString());
        if (deptid == 0)
            sqlquery = "select e.empid,e.empname,e.empjob,e.empsal,d.deptname from emp1 e,dept1 d where e.deptid=d.deptid";
        else
            sqlquery = "select e.empid,e.empname,e.empjob,e.empsal,d.deptname from emp1 e,dept1 d where e.deptid=d.deptid and e.deptid=" + deptid;
        da = new SqlDataAdapter(sqlquery, con);
        ds = new DataSet();
        da.Fill(ds, "emp");
        gview1.DataSource = ds.Tables["emp"];
        gview1.DataBind();
    }
}

Wednesday, 27 December 2017

How To Insert Data Into Xml File in ASP.Net

To insert data into the xml file in ASP.Net we should have follow the following steps:

1)  Open Visual Studio
2) Go to File=>New=>Web Site( give the name as insertdataxml)
3)  Add a new webform into the project named it as:(Dataxml.aspx) design it as following:


4)Add a Xml file into the project and name it as ("EmployeeData.Xml") and add the following into the xml file:
                  <employeeinformation>
                   </employeeinformation>
5)Double click on the Submit button and write the following:

using System.Xml;
using System.Data;


namespace Gridview_with_checkbox
{
    public partial class Dataxml : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ShowFileData();
            }
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(Server.MapPath("EmployeeData.xml"));
            XmlElement ParentElement = xmldoc.CreateElement("Employee");

            XmlElement name = xmldoc.CreateElement("Name");
            name.InnerText = txtename.Text;

            XmlElement job = xmldoc.CreateElement("Job");
            job.InnerText = txtempjob.Text;

            XmlElement sal = xmldoc.CreateElement("Sal");
            sal.InnerText = txtempsal.Text;

            ParentElement.AppendChild(name);
            ParentElement.AppendChild(job);
            ParentElement.AppendChild(sal);
            xmldoc.DocumentElement.AppendChild(ParentElement);
            xmldoc.Save(Server.MapPath("EmployeeData.xml"));

            ShowFileData();
        }

        private void ShowFileData()
        {
            using(DataSet ds=new DataSet ())
            {
                ds.ReadXml(Server.MapPath("~/EmployeeData.xml"));
                if(ds.Tables.Count>0)
                {
                    gview1.DataSource = ds.Tables[0];
                    gview1.DataBind();
                }
            }
        }
    }
}


5)Now run the page and enter the data into the textboxes and click on the submit button then you will see the data should be inserted into the xml file.

STAR TRIANGLE PATTERN

2.After Writting the above code see the output given below.