Translate

Wednesday, 9 December 2015

CRUD Operations in Classic ASP

Crud Operations In Classic ASP
First Open Visual Studio
 Goto File-New Web Site- Templates -Visual Basics - Asp.net Empty Website

Create website and add new item ->select html template- give name as List.asp


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

<head>
    <title></title>
    <script src="Scripts/jquery.fancybox-1.3.4.js"></script>
    <h1>Sample Classic Asp </h1>
    <%

dim db_connection

db_connection = "Provider=SQLOLEDB.1;Server=WEBDEL33\SQL2008R2;Database=Kavitha;Uid=sa; Pwd=Pwd4sql2008;"


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>
    <table border="1">
        <tr>
            <td>Edit</td>
            <td>Delete</td>
            <td>Name</td>
            <td>Mobile</td>
            <td>Email</td>
            <td>City</td>
        </tr>
        <%
             
              while not rs.eof
        %>
        <tr>

            <td><a href="add.asp?Name=<%=rs("Name")%>" class="news_frm"><%=rs("Name")%></a></td>
            <td><a href="Delete.asp?Id=<%=rs("Id")%>" class="news">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 id="frmshow" style="display: none">
        <iframe src="/add.asp" width="400" height="400"></iframe>
    </div>


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



New Member/Update in add.asp:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
     <script type="text/javascript">
         function Submit_page() {
             if ($("#Name").val() == "") {
                 alert("Enter Name.");
                 return false;
             }
             if ($("#Text1").val() == "") {
                 alert("Enter Mobile.");
                 return false;
             }
             if ($("#Text2").val() == "") {
                 alert("Enter Email.");
                 return false;
             }
             if ($("#Text6").val() == "") {
                 alert("Enter Password.");
                 return false;
             }
             else
                 return true;
         }

        </script>
   

  

    <%

dim db_connection

db_connection = "Provider=SQLOLEDB.1;Server=WEBDEL33\SQL2008R2;Database=Kavitha;Uid=sa; Pwd=Pwd4sql2008;"


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 top 1 * 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">
    <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%>" /></td>
        </tr>
         <tr>
            <td>
                Mobile
            </td>
            <td><input type="text" id="Text1" name="Mobile" maxlength="10" value="<%=Mobile%>"/></td>
        </tr>
         <tr>
            <td>
                Email
            </td>
            <td><input type="text" id="Text2" name="Email" value="<%=Email%>"/></td>
        </tr>
         <tr>
            <td>
                Country
            </td>
            <td><input type="text" id="Text3" name="Country" value="<%=Country%>"/></td>
        </tr>
         <tr>
            <td>
                State
            </td>
            <td><input type="text" id="Text4" name="State" value="<%=State%>"/></td>
        </tr>
         <tr>
            <td>
               City
            </td>
            <td><input type="text" id="Text5" name="City" value="<%=City%>"/></td>
        </tr>
         <tr>
            <td>
                Password
            </td>
            <td><input type="text" id="Text6" name="Password" value="<%=Password%>"/></td>
        </tr>
         <tr>
            <td>
                Address
            </td>
            <td><input type="text" id="Text7" name="Address" value="<%=Address%>"/></td>
        </tr>
       
        <tr>
         
            <td>
                <input type="submit" id="btnsubmit" value="Submit" onclick="Submit_page()" /><div id="post_result"></div>
            </td>
            <td>
               
            </td>
        </tr>
    </table>
        </form>
  
</body>
  

</html>

Updating /Inserting in posting.asp:

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

dim db_connection

db_connection = "Provider=SQLOLEDB.1;Server=WEBDEL33\SQL2008R2;Database=Kavitha;Uid=sa; Pwd=Pwd4sql2008;"


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= "INSERT INTO Address (Name,Mobile,Email,Address,Country,State,City,Password) values('" &(Name)& "','"&(Mobile) & "','"&(Email)&"','"&(Address)&"','"&(Country)&"','"&(State)&"','"&(City)&"','"&(Password)&"')"

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



Delete Member in Delete.asp:

     <%

dim db_connection

db_connection = "Provider=SQLOLEDB.1;Server=WEBDEL33\SQL2008R2;Database=Kavitha;Uid=sa; Pwd=Pwd4sql2008;"


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("database.asp")
        end if
 %>
   <!--<script type="text/javascript">alert("Successful!");</script>-->



Thursday, 3 December 2015

How to check Duplicate row values in Html table using jquery


 Check duplicete values in html table using Jquery in below ways

First Way:

    <script src="Scripts/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        $(function () {

            function IsDuplicate(btnId, tableId) {
                if ($(btnId).length > 0 && $(tableId).length > 0) {
                    $(btnId).click(function () {
                        alert($('#' + $(txtvalue).val() + '').length);
                        if ($(tableId).find('#' + $(txtvalue).val() + '').length > 0) {
                            alert('d');
                        } else {
                            alert('s');
                        }
                    });
                }
                else { return false; }
            }

            IsDuplicate('#btnDuplicate', 'table');
        })

    </script>
Second Way:


<script>
        $(document).ready(function () {
            $("#btnDuplicate").click(function () {
                var count = 0;
                $('#tblcheck tr').each(function () {
                
                    var customerId = $(this).find("td").eq(1).html();
                    if (customerId == $("#txtvalue").val()) {
                       count++
                    }
                  
                });
                if (count > 0) {
                    alert("Duplicate");
                }
                else {
                    alert("No Duplicates");
                }
            });
        });

    </script>


Html Table:

</head>
<body>
    <table>
        <tr>
            <th>Id</th>
            <th>Name</th>
        </tr>
        <tr id="1">
            <td>1</td>
            <td>Kavitha</td>
        </tr>
        <tr id="2">
            <td>2</td>
            <td>Hello</td>
        </tr>
        <tr id="3">
            <td>3</td>
            <td>Hello1</td>
        </tr>
    </table>
    <input type="text" id="txtvalue" />
    <input type="button" id="btnDuplicate" value="Duplicate" />
</body>

</html>

Wednesday, 25 November 2015

Static and Dynamic Droprdownlists in MVC

Here How to bind Dropdown in Static and Dynamically.


Static DropDownList:
  
            @Html.DropDownListFor(m=>m.CountryName,new List<SelectListItem>{
                    new SelectListItem{ Text="India", Value = "1" },
                    new SelectListItem{ Text="US", Value = "0" },
new SelectListItem{ Text="UK", Value = "2" }
                 })

Dynamic DropDownList:

  @Html.DropDownListFor(m=>m.CountryName,new SelectList((System.Collections.IEnumerable)ViewData["country"],"value","text"),"Select")