2013-05-22 3 views
0

렌즈 데이터와 옵션을 채우기 위해 사용하는 asp/razor 웹 페이지가 있습니다.지난 Null 오류를 얻는 방법?

존재하는 SID 값을 반환하고 싶지 않으면 비워 두겠다. 한 Statment이 작업을 수행하는 경우

내가 사용하고 있지만, 브라우저에 오류보고 :


Server Error in '/' Application. 
-------------------------------------------------------------------------------- 
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'SID' does not exist in the current context 

Source Error: 

Line 238:   <div class="row"> 
Line 239:    <span class="label"><label for="salesid">SalesID:</label></span> 
Line 240:    <input type="text" name="salesid" id="salesid" [email protected] size="15" /> 
Line 241:   </div>} 
Line 242:   else {@message;} 

Source File: ~\DiscountCustomers.cshtml Line: 240 

-------------------------------------------------------------------------------- 
@{ 
    Layout = "~/_SiteLayout.cshtml"; 

    var db = Database.Open("A-LensCatFE-01SQL") ; 

    var CustomerCode = UrlData[0]; 

    var message = ""; 

    // vars for dropdowns: 
    var ListSRP =db.Query("Select * FROM lstSRPBasedOn"); 
    var LensName = db.Query("Select Form, ShortName FROM dbo.qryLAStyleMin ORDER BY Form"); 

    // vars for modal forms insert data: 
    var query = ("Select * from dbo.qryCustomersAll Where CustomerCode= @0"); 
    var data = db.QuerySingle(query, CustomerCode); 
    var emcid = data.CID; 

    var query1 = ("Select CatID from dbo.qryCustomersAll Where CustomerCode= @0"); 
    var catid = db.QueryValue(query1, CustomerCode); 

    var query3 =("Select * from dbo.qryPromo2 Where [email protected]"); 
    var data3 = db.QuerySingle(query3, CustomerCode); 

    if (data3 != null) 
       {var SID = data3.SalesID;} 
       else 
       { message="Data not found";} 

    } 
--------------------------------------------------------------- 
@if (data3 != null){ 
      <div class="row"> 
       <span class="label"><label for="salesid">SalesID:</label></span> 
       <input type="text" name="salesid" id="salesid" [email protected] size="15" /> 
      </div>} 
      else {@message;} 
--------------------------------------------------------------- 

내가 잘못하고있는 중이 야 무엇을? 이 문제를 어떻게 해결할 수 있습니까? 고맙습니다.

답변

0

SIDif 문 내부에 선언되어 있으므로 범위에 포함되지 않습니다. 선언문을 if 성명 외부로 이동하십시오.

int SID = 0; 
if (data3 != null) 
    {SID = data3.SalesID;} 
else 
    { message="Data not found";} 
(SID 가정하면 int이다)
관련 문제