zeeshan akram

zeeshan akram

  • 1.3k
  • 325
  • 16.6k

SqlQuery return -1 in EF using MVC

Jul 8 2020 3:15 AM

I want to run query in EF but when I run this query in SQL SERVER MANAGEMENT THEN return "00002" but when I run in EF, this query return -1. I don't know what is happing any senior can you tell where i am wrong. I also share the screenshot of the query result where you can see the return result. error: "-1".

I am sharing the C# function where I fetch the query from the database and call the function using jquery. function working properly but query result is wrong . Why? I don't know.
when i use SQLQUERY then it will return whole query as a string like " select RIGHT('00000' + cast(ISNULL(MAX(User_Id),0)+1 as varchar(5)) + '',6)from secUsers "
 
 C#
  1. public int Maxnumber()  
  2. {  
  3.   
  4.     int result = _db.Database.ExecuteSqlCommand("select RIGHT('00000' + cast(ISNULL(MAX(User_Id),0)+1 as varchar(5)) + '',6)from secUsers");  
  5.   
  6.     return result;  
  7. }  
  8.   
  9. public JsonResult max_UserID()  
  10. {  
  11.     var mNo= _IAccount.Maxnumber();  
  12.     return Json(mNo, JsonRequestBehavior.AllowGet);            
  13. }  
Jquery
  1. function MaxNo() {  
  2.           $.ajax({  
  3.               type: 'GET',  
  4.               url: '@Url.Action("max_UserID")',  
  5.               dataType: 'json',  
  6.               data: {},  
  7.               success: function (mNo) {  
  8.   
  9.                   $("#userid").val(mNo);  
  10.               },  
  11.               error: function (ex) {  
  12.                   var r = jQuery.parseJSON(response.responseText);  
  13.                   alert("Message: " + r.Message);  
  14.                   alert("StackTrace: " + r.StackTrace);  
  15.                   alert("ExceptionType: " + r.ExceptionType);  
  16.               }  
  17.           });  
  18.           return false;  
  19.       }  
 

Answers (2)