저는 C#을 처음 사용하므로 로그인 양식에 문제가 있습니다.로그인시 상태 당 정지?
제출 버튼을 누를 때마다 내 사용자 클래스가 "admin"이 아닌 경우 로그인 양식으로 다시 나타납니다. 그래서 조건이 사실이 아닐 때 제 진술이 멈 춥니 다. 여기 내 코드가있다. 내 초보자 제한 여기에 대한 죄송합니다
-------- 편집 내가 무엇을 가지고 : 가 사용자가 가지고있는 역할에 따라 사용자 이름과 역할 와 SQL 테이블이 다른 양식을로드
// Compare strings
private bool CompareStrings(string string1, string string2)
{
return String.Compare(string1, string2, true, System.Globalization.CultureInfo.InvariantCulture) == 0 ? true : false;
}
// button on Login form
public void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection UGIcon = new SqlConnection();
UGIcon.ConnectionString = "Data Source=BVSQL; Initial Catalog=BV1;user id=jose; password=jones6;";
UGIcon.Open();
SqlCommand cmd = new SqlCommand("SELECT ISNULL(bvuser, '') AS stUsername, ISNULL(bvpassword,'') AS stPassword, ISNULL(bvclass, '') AS stRole FROM BVusertable WHERE bvuser='" + textBox1.Text + "' and bvpassword='" + textBox2.Text + "'", UGIcon);
SqlDataReader dr = cmd.ExecuteReader();
string userText = textBox1.Text;
string passText = textBox2.Text;
//string stRole = "admin";
dr.Read();
{
if
(this.CompareStrings(dr["stUsername"].ToString(), userText) &&
this.CompareStrings(dr["stPassword"].ToString(), passText)
)
{
if (this.CompareStrings(dr["stRole"].ToString(), "admin"))
{
this.DialogResult = DialogResult.OK;
}
else if (this.CompareStrings(dr["stRole"].ToString(), "user"))
{
this.DialogResult = DialogResult.No;
}
}
else
{
//MessageBox.Show("Error");
}
}
dr.Close();
UGIcon.Close();
}
catch (Exception ex)
{
MessageBox.Show("Login Falied");
}
}
여기 Programs.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace BV_SOFT
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Loginf fLogin = new Loginf();
if (fLogin.ShowDialog() == DialogResult.OK)
{
Application.Run(new Home2());
}
else
if (fLogin.ShowDialog() == DialogResult.No)
{
Application.Run(new Home3());
}
else
{
Application.Exit();
}
'this.CompareStrings' 메소드에는 무엇이 있습니까? 왜 그 메소드를 호출하는 대신에'=='를할까요? – sparky68967
@ sparky68967 - 대소 문자를 구분하지 않는 비교를 수행 할 수 있습니다 (예 :). – ChrisF
@ChrisF 사용자 이름은 괜찮을 지 모르지만 비밀번호는 권하지 않습니다. – sparky68967