Sunday, 15 March 2020

how to create user in sql server and grant select permission only


Follow the 4 steps for creating user and grant permission:

Example:

step 1: create LOGIN rochelle with password ='admin@123'
step 2: use DatabaseName
step 3: create user s_rochelle for login rochelle
step 4: grant select to s_rochelle
Step 5: GRANT SELECT ON SCHEMA :: wmwhse2 TO DBUAT02 WITH GRANT OPTION;

Wednesday, 11 March 2020

Create new APPPOOL in sql server

IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOL\MLM')
BEGIN
    CREATE LOGIN [IIS APPPOOL\MLM]
      FROM WINDOWS WITH DEFAULT_DATABASE=[master],
      DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [MLMWebDatabaseUser]
  FOR LOGIN [IIS APPPOOL\MLM]
GO
EXEC sp_addrolemember 'db_owner', 'MLMWebDatabaseUser'
GO

Friday, 31 January 2020

Custom Polyline with multiple icons in google map


<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style type="text/css">
html,
body,
#map {
  height: 100%;
  margin: 0;
  padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer
        src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
<script type="text/javascript">
  function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 3,
    center: {
      lat: 0,
      lng: -180
    },
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
 var lineSymbol=[];
 var icons=[];
 var time=["Flair Towers - South Towers<br/>10:30 AM","Flair1 Towers - South Towers <br/>11:00 AM","IBM Plaza<br/>11:35 AM","Cebu Pecific<br/>12:15 PM"];
  var path = [{lat: 37.772,lng: -122.214},
    {lat: 21.291,lng: -157.821},
    {lat: -18.142,lng: 178.431},
    {lat: -27.467,lng: 153.027}
  ];
  var infowindow = new google.maps.InfoWindow();
  if(path.length>0){
    for(var j=0;j<path.length;j++){
      lineSymbol.push(new google.maps.Marker({icon:{anchor:new google.maps.Point(16,16), origin: new google.maps.Point(0, 0),scaledSize: new google.maps.Size(32, 32),size: new google.maps.Size(64, 64),url: "D:\\truck.png"},position: path[j],map:map}));
    icons.push({icon: lineSymbol[j],offset:"100%"});
 
      google.maps.event.addListener(lineSymbol[j], 'click', (function(marker, time, infowindow) {
        return function(evt) {
          infowindow.setContent(time);
          infowindow.open(map, marker);
        }
      })(lineSymbol[j], time[j], infowindow));
     google.maps.event.trigger(lineSymbol[j], 'click');
    }
  }

  var Line = new google.maps.Polyline({
    path: path,
    geodesic: true,
    strokeColor: "#35495e",
    strokeOpacity: 0.8,
    strokeWeight: 4,
    icons:icons,
  });
  debugger;
  Line.setMap(map);
   var bounds = new google.maps.LatLngBounds();
   for (var i = 0; i < Line.getPath().getLength(); i++) {
    bounds.extend(Line.getPath().getAt(i));
  }
  map.fitBounds(bounds);

}
</script>
</body>
</html>


Wednesday, 29 January 2020

How to get list through ajax jquery in c#

Here is simplify method with example please read and practice carefully then definitely you'll do this.

The first method is using get method..

$.ajax({
url:"/Home/GetUserList", /// this is URL  "HOME"- COntroller name, GetUserList-Method Name
type:"GET",   /// define type GET or POST
datatype:"json", /// datatype format
Content-Type:"application/json",
data:{}
success:function(response){
    alert("We got it user list").
}
error: function(response){
alert("we can't found the user list, there is something error");
}
})

Tuesday, 28 January 2020

Get all column names from database table with specific schema in SQL Server

Many times there’s a requirement to get all columns for a particular table in database. Hence here is a SQL Query that does that.


SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Your Table Name'
ORDER BY ORDINAL_POSITION

Monday, 20 January 2020

How to control image shown error if the image not found on the location

I like to use this way, so that whenever original image is not available you can load your default image that may be your favorite smiley or image saying Sorry ! Not Available, But in case if both the images are missing you can use text to display. where you can also you smiley then. have a look almost covers every case.


<img src="path_to_original_img/img.png"  alt="Sorry! Image not available at this time" 
       onError="this.onerror=null;this.src='<?=base_url()?>assets1/img/default.jpg';">

Friday, 27 December 2019

How to Executing SQL Query in Entity Framework and Linq MVC C#

I will explain to you how we can use different types of SQL Query methods.

Introduction

 In this post, we will see how to execute native SQL queries, using DB Context.

 You can execute SQL queries using the following types of SQL Query methods. 

 1- SQL Query for a specific entity type.

 2- SQL Query for a primitive data type.

 3- SQL commands.


Let’s start.


SQL Query for a specific entity type


We can use SQLQuery() method to write SQL queries which return an entity object.


Example:


==============================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

var customerList = db.Customers.SqlQuery("Select * From Customers").ToList<Customers>();  

==============================================================

The code, shown above, selects all the data rows from customer's table. I would like to add that columns returned by SQLQuery must match the property of an entity type, otherwise it will throw an exception.


SQL Query for a primitive data type


In this type, the SQL Query() method will return any primitive types created using the SQL Query method.



Example:

========================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

int customerId = db.Database.SqlQuery<int>("Select customerId From Customers where customerName='MAHDI'").FirstOrDefault<int>(); 

========================================================

SQL commands


We can use ExcecuteSqlCommand() method to ensure the CRUD operation.


Example:

===========================================================
//DbContext  

DbPersonnesEntities db = new DbPersonnesEntities();  

int result = db.Database.ExecuteSqlCommand("delete from Customers where customerId = 100");  
===========================================================


As you can see, code displayed above will delete a customer that has 100 as customerId.

redirect to new page from jquery

  function foo(id) { var url = ' @Url . Action ( "Details" , "Branch" , new { id = "__id__" })'...