Tuesday, September 25, 2018

Learn Asp.net MVC for Free

Check some very useful articles for Asp.net MVC,  i will help  you to learn Asp.net MVC for Free of cost , check this link http://www.webtrainingroom.com/mvc

 learn asp.net mvc for free

Sunday, June 24, 2018

How to get current page url in Asp.net MVC

If you want to capture current page url in Asp.Net MVC ,
just type @Request.Url.AbsoluteUri . this will get you full url  

Tuesday, June 12, 2018

How to implement transaction in ADO.Net

In Ado.net we can implement transaction for Single Database and also multiple database ( known as distributed database )

This is how we can implement transaction into single database using Ado.net object

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text; 


void transactionTest1()
{
string strConnString = "myconnectionstring";
            SqlTransaction objTrans = null;
            using (SqlConnection objConn = new SqlConnection(strConnString))
            {
                objConn.Open();
                objTrans = objConn.BeginTransaction();
                SqlCommand objCmd1 = new SqlCommand("insert into tableOne values(100)", objConn);
                SqlCommand objCmd2 = new SqlCommand("insert into tableTwo values(200)", objConn);
                try                {
                    objCmd1.ExecuteNonQuery();
                    objCmd2.ExecuteNonQuery();
                    objTrans.Commit();
                }
                catch (Exception)
                {
                    objTrans.Rollback();
                }
                finally                {
                    objConn.Close();
                }
            }
}

Another way to use transaction can be 

 using (var transaction = new TransactionScope())

                        {
//data manipulation done here

transaction.Complete();
}

Wednesday, May 29, 2013

Schedule Job with store procedure, store procedure with cursor

This is an example of  scheduling a sql job with a store procedure, also writing a cursor with in a store procedure. 

alter procedure uspInitiateAdmission
As
BEGIN 
   declare @QueryId bigint, @StudentId bigint, @PaymentId bigint, 
   @RequestStatus int , @PaymentStatus int 
               
     declare curTemp cursor for
        /*
        fetch data based on your query and where clause
        */
     SELECT  t2.StudentRequestId, t2.RequestStatus, t2.RequestStatus   
        FROM tbStudentPayment t1 right outer JOIN tbSchoolManagementBoard t2
                      ON t1.QueryId = t2.StudentRequestId
                      where t2.RequestStatus <> 4 and
                      DATEADD(dd, 3, t2.RequestDateTime) >= GETDATE() and
                      t2.StudentRequestId not in (select QueryId from tbStudentPayment)
                            
  Open  curTemp     
        fetch next from curTemp into @QueryId, @PaymentStatus, @RequestStatus

    while @@FETCH_STATUS =0
        begin
                                   
            INSERT INTO [tbStudentPayment]
           ([QueryId]
           ,[StudentId]
           ,[PaymentId]          
           ,[ActionDate]
           ,[Status])
            VALUES
           (@QueryId
           ,@StudentId
           ,1
           ,GETDATE()
           ,'Admission Request')

    END
Close curTemp
Deallocate curTemp
    
END


populating child dropdownlist using JSON Jquery in MVC4 Razor

here i am sharing an example of populating child dropdownlist when changing some value parent dropdownlist

Step 1:
Write two dropdownlist country and state

@Html.DropDownListFor(m => m.CountryId,
            new SelectList(ViewBag.Countries, "Value", "Text"),
            "Select Country", new { data_url = Url.Action("GetStates") })

 @Html.DropDownListFor(m => m.StateId,
            new SelectList(ViewBag.States, "Value", "Text"),
            "Select State")

Step 2:
Write a method in controller which will return JsonResult of states, so that can be consumed using jquery , and populate the state list

public JsonResult GetStates(int countryId)
        {
            IEnumerable< tbState > states = _SecurityService.GetStates(countryId);
         
            return Json(states, JsonRequestBehavior.AllowGet);

         
        }

Step : 3
now lets look at the script, where we get the JSON result and populate the state dropdownlist

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

< script >
    $(document).ready(function () {

        $('#CountryId').change(function () {

            var url = $(this).data('url');

            var data = { countryId: $(this).val() };

            $.getJSON(url, data, function (GetStates) {
                var ddlState = $('#StateId');
                ddlState.empty();
                ddlState.append($('< option/ >', {
                    value: 0,
                    text: "Select State"
                }));

                $.each(GetStates, function (index, StateObj) {
                    ddlState.append($('< option/ >', {
                        value: StateObj.StateId,
                        text: StateObj.State
                    }));

                });
            });
        });
    });
< /script >