2016-10-10 113 views
0

我使用小巧玲珑选择数据形式Mssql中选择数据,它导致显示“空”使用小巧玲珑从MS SQL

(使用存储过程,列表以获取数据,以及“myDictionary [0] .Account”和myDictionary [0] .Password获取详细信息),

但MS SQL数据库有数据。

我该如何修复代码?谢谢。

public void Do_Click(object sender, EventArgs e) 
    { 
     string strAccount = Request.Form["userAccount"]; 
     string strPassword = Request.Form["userPwd"]; 

     using (var conn = new SqlConnection(strConn)) 
     { 
      try 
      { 
       conn.Open(); 

       List<LoginModel> myDictionary = 
        conn.Query<LoginModel>(@"uspSelectLoginChk", 
              new { LoginAcc = strAccount, LoginPsd = strPassword }, commandType: CommandType.StoredProcedure).ToList(); 
       string strAccountChk = myDictionary[0].Account; 
       string strPASChk = myDictionary[0].Password; 

       conn.Close(); 


       if (strAccountChk != null && strAccountChk != null) 
       { 

        Response.Redirect("test.aspx"); 
       } 
       else 
       { 

       } 


      } 
      catch (Exception ex) 
      { 
       response.write(ex.ToString()); 
      } 
     } 

    } 

回答

0

试试这个,

// Modified your code 
public void Do_Click(object sender, EventArgs e) 
{ 
    string strAccount = Request.Form["userAccount"]; 
    string strPassword = Request.Form["userPwd"]; 
    var _para = new DynamicParameters(); 
    _para.Add("@LoginAcc", strAccount); 
    _para.Add("@LoginPsd", strPassword); 
    var _list = _con.Query<LoginModel>("uspSelectLoginChk", _para, commandType: CommandType.StoredProcedure); // _con is SqlConnection _con = new SqlConnection("your connection string") 
    if(_list != null) { 
     Response.Redirect("test.aspx"); 
    } 

} 
0

您需要检查: 在SQL中使用参数可在调试代码视图下执行SP。

example: 
    exec uspSelectLoginChk 'LoginAccValue', 'LoginPsdValue' 

如果在SQL中的任何数据来执行,你的代码错误,如果没有数据,你可以用一个数据调试结果之前插入数据。 感谢