2017-12-09 8 views
-2
Encoding.ASCII.GetString(o.Username) == textBox1.Text 

이것은 이전에이 문제를 해결하기 위해 제공 한 코드입니다. 내 코드에 어디에 넣을 지 모르겠습니다. 도와주세요!! 컴파일 할 때연산자 '=='은 'byte []'및 'string'유형의 피연산자에 적용 할 수 없습니다. 수정 됨

private void button1_Click(object sender, EventArgs e) 
{ 
    if (string.IsNullOrEmpty(textBox1.Text)) 
    { 
     MessageBox.Show("Please Enter your username.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
     textBox1.Focus(); 
     return; 
    } 
    try 
    { 
     using (DataEntities test = new DataEntities()) 
     { 
      var query = from o in test.Users 
         where o.Username == textBox1.Text && o.Password == textBox2.Text 
         select o; 
      if(query.SingleOrDefault() != null) 
      { 
       MessageBox.Show("You have been successfully logged in.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        //Add your code process login here 
      } 
      else 
      { 
       MessageBox.Show("Your username or password is incorrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    } 
} 
+0

[게시 한 질문] (https://stackoverflow.com/questions/47707289/operator-cannot-be-applied-to-operands-of-type-byte-and-string)을 다시 게시하지 마십시오.)을 눌러 편집하십시오. 게시물의 [edit] (https://stackoverflow.com/posts/47707289/edit) 링크를 클릭하기 만하면됩니다. 이 질문은 삭제해야하며 다른 하나는 문제가있는 모든 문제를 해결하기 위해 편집해야합니다. –

+0

'o.Password == textBox2.Text' -> 당신은 ** 해싱 ** 사용자 암호가 있어야합니다. 이상하게도 소금이 있어야합니다. 간단하게 평등 검사를 할 수는 없습니다. 누군가 데이터베이스를 해킹하면 사용자 세부 정보와 일반 텍스트 암호가 모두 있습니다. – john

답변

-2

당신은 바로이 오류가 있어요 :

이 오류가있는 부분입니까?

귀하의 문제는 실제로 귀하가 귀하의 질문에 대해 따옴표를 사용하지 않았다고 생각합니다.

이 :

var query = from o in test.Users 
where o.Username == textBox1.Text && o.Password == textBox2.text 
select o; 

가되어야한다

var query = "from o in test.Users" + 
"where o.Username == textBox1.Text && o.Password == textBox2.text" + 
"select o"; 

쿼리 문자열입니다, 그래서 당신은 바로 따옴표와 =의 모든 것을 둘러싸고해야합니다. 이것은 컴파일러에게 더 많은 코드가 아니라 문자열 리터럴임을 알려줍니다.

+0

SQL 쿼리가 아닌 Linq입니다. SQL 쿼리 일지라도 유효한 쿼리는 아닙니다. Linq 질의 구문 [here] (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-linq-query-operations)에 대해 배울 수 있습니다. – john

관련 문제