Wednesday, 2 January 2019

How to use SQL Store procedure in C# || How to Get Latest Record Id afte...











create proc sP_insertadmin

(

@ad_id int out,

@ad_name nvarchar(50),

@ad_password nvarchar(50)

)

as

begin



insert into tbl_Admin values(@ad_name,@ad_password);



select @ad_id=SCOPE_IDENTITY();



end

-------------------------------------------------------------------------------------------------



 public string Addwithstoreproc(Admin ad)

        {

            string msg = null;

            SqlConnection conn = new SqlConnection(connectionstring);

            try

            {

                conn.Open();

                SqlCommand cmd = new SqlCommand("sP_insertadmin", conn);

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@ad_name", SqlDbType.NVarChar, 50).Value = ad.name;

                cmd.Parameters.Add("@ad_password", SqlDbType.NVarChar, 50).Value = ad.password;

               SqlParameter para = new SqlParameter();

                para.SqlDbType = SqlDbType.Int;

                para.Direction = ParameterDirection.Output;

                para.ParameterName = "@ad_id";

                cmd.Parameters.Add(para);

                cmd.ExecuteNonQuery();

                msg = para.Value.ToString();



            }

            catch (Exception)

            {

                msg = "Data couldnot inserted...........";



            }





            return msg;



        }

---------------------------------------------------------------------------

Sunday, 23 December 2018

Get Data Through Ajax || Ajax with asp.net mvc in hindi/urdu





<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script src="~/Scripts/jquery-1.10.2.js"></script>

<div class="container">



    <table class="table table-responsive table-striped">

        <thead>

            <tr>

                <th>ID</th>

                <th>NAME</th>

                <th>EMAIL</th>

                <th>ADDRESS</th>



            </tr>

        </thead>



        <tbody id="ListData">





        </tbody>



    </table>







</div>









<script>



    $(document).ready(function () {

        GetData();



        function GetData()

        {



            var html = '';



            $.ajax({



                type: 'GET',

                url: '/Home/GetAllEmployee',

                success: function (response)

                {



                    $.each(response, function (key, item)

                    {



                        html += "<tr> <td>" + item.Id + " <td>  <td>" + item.Name + " <td> <td>" + item.Email + " <td>  <td>" + item.Address + " <td></tr>";

                    });



                    $("#ListData").append(html);



                }



            });







        }













    });









</script>

Thursday, 13 December 2018

How to pass data from asp.net mvc to angularJS || step by step in Hindi...





module:

var myapp;
(function () {
    myapp = angular.module('my-employees', []);
}
)();

service:

myapp.service('employeeService', function ($http)
{


    this.getAllEmployees = function ()
    {
        return $http.get('/Home/GetAllEmployee');
    }
   

});

controller:

myapp.controller('employee-controller', function ($scope, employeeService)
{


    //Loads all Employee records when page loads
    loadEmployees();
    
    function loadEmployees()
    {
        var EmployeeRecords = employeeService.getAllEmployees();



        EmployeeRecords.then(function (d)
        {
            $scope.Employees = d.data;
        },
        function ()
        {
            alert("Error occured while fetching employee list...");

        });



    }



});

Index:


<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />

<div class="container" ng-app="my-employees" ng-controller="employee-controller">
    <div class="row">
        <br />
        <br />

<input type="search"  ng-model="search" class="form-control"/>


    </div>

    <table class="table table-responsive table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>SALARY</th>
                <th>DEPARTMENT</th>

            </tr>
        </thead>


        <tbody>
            <tr ng-repeat="x in Employees|filter:search">
                <td>{{x.emp_id}}</td>
                <td>{{x.emp_name|uppercase}}</td>
                <td>{{x.emp_salary |currency}}</td>
                <td>{{x.dep_name}}</td>

            </tr>


        </tbody>



    </table>



</div>


<script src="~/AngularJSapp/Module.js"></script>
<script src="~/AngularJSapp/Service.js"></script>
<script src="~/AngularJSapp/controller.js"></script>

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...