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
 %>