2016-11-12 22 views
0
{ 
    public DataTable EmpLoginbyId() 
    { 
     SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true"); 
     SqlCommand cmd = new SqlCommand(); 
     DataTable dt = new DataTable(); 
     SqlDataAdapter adp = new SqlDataAdapter("EmpLoginbyId", con); 
     cmd.CommandType = CommandType.StoredProcedure; 
     adp.Fill(dt); 
     return dt; 
    } 
    public void EmpLogin(string Email, String Password) 
    { 

     SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true"); 
     SqlCommand cmd = new SqlCommand("EmpLogin", con); 
     cmd.CommandType = CommandType.StoredProcedure; 
     cmd.Parameters.AddWithValue("@Email", Email); 
     cmd.Parameters.AddWithValue("@passward", Password); 



     con.Open(); 
     cmd.ExecuteNonQuery(); 
     con.Close(); 
    } 

保護無效的button1_Click(對象發件人,EventArgs的){ 錯誤而做頁面登錄爲ASP.NET應用程序和SQL服務器

 try 
     { 
      Session["UID"] = Lgn.EmpLogin(TxtUN.Text, TxtPW.Text); 
      int? UID = Convert.ToInt32(Session["UID"].ToString()); 
      DataTable dt = new DataTable(); 
      dt = Lgn.EmpLoginbyId(Convert.ToInt32(UID)); 
      string Username = dt.Rows[0]["UserName"].ToString(); 
      //string Username = dt.Rows[0]["UserName"].ToString(); 
      Session["ETID"] = Convert.ToInt32(dt.Rows[0]["UserTypeID"].ToString()); 
      if (Username == null) 
      { 
       Session["UserName"] = Username.ToString(); 

      } 
      if (UID.HasValue) 
      { 
       Response.Redirect("Admin.aspx"); 
      } 


     } 
     catch { } 
    } 

,這是我的類代碼它給我這個錯誤 錯誤1無法隱式轉換類型「無效」到「對象」
錯誤2未重載方法「EmpLoginbyId」需要1個參數

回答

0

第一個錯誤是因爲存在是EmpLogin retur ning void並且你正試圖將它分配給一些無效的對象。所以要麼從函數返回一些值,要麼將賦值移除到會話對象。

第二個錯誤是有效的,因爲EmpLoginById在其簽名中沒有任何參數。因此,通過刪除UID來修改簽名或調用函數。

相關問題