私はユーザー名とパスワードでログインウィンドウを作っています。私はユーザー情報を持っているデータテーブルを持っており、ユーザーがログインしようとすると(コードの最後に)else..ifステートメントを使用しています。ユーザー名とパスワードを確認して、テーブルにあるものと一致することを確認します。それがなければ、メッセージボックスが現れると思われていました。また、最後のelse ... if文の方に、ユーザーJANITORはまったくログインしません!この問題の原因は何ですか?彼らは最後のユーザーJANITORと私のメッセージボックスが表示されていないことを除いてすべて正常にログインします!それ以外の場合は、私のフォームでif文が動作しない...?代わりにtry-catchを使用できますか?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace LOGINPAGE
{
public partial class Room : Form
{
public Room()
{
InitializeComponent();
PassText.PasswordChar = '*';
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
FloorSelection ss = new FloorSelection();
ss.Show();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
}
private void EXIT_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void xButton1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Mohamed\Documents\UserData.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("Select Count (*) From dbo.[LOGIN] where username='" + UserText.Text + "' and Password ='" + PassText.Text + "'", con);
FloorSelection ss = new FloorSelection();
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
SqlDataAdapter sda1 = new SqlDataAdapter("Select TYPE From dbo.[LOGIN] where username='" + UserText.Text + "' and Password ='" + PassText.Text + "'", con);
FloorSelection ss1 = new FloorSelection();
DataTable dt1 = new DataTable();
sda1.Fill(dt1);
if (dt1.Rows[0][0].ToString() == "FACULTY")
{
this.Hide();
FACULTY ff = new FACULTY();
ff.Show();
}
else if (dt1.Rows[0][0].ToString() == "ADMINISTRATOR")
{
this.Hide();
ADMINISTRATOR Ad = new ADMINISTRATOR();
Ad.Show();
}
else if (dt1.Rows[0][0].ToString() == "JANITOR")
{
this.Hide();
JANITOR jt = new JANITOR();
jt.Show();
}
else
{
MessageBox.Show("Please check your username and password");
}
}
}
private void label3_Click(object sender, EventArgs e)
{
label3.BackColor = Color.Transparent;
}
private void UserText_TextChanged(object sender, EventArgs e)
{
UserText.BackColor = Color.Empty;
}
private void PassText_TextChanged(object sender, EventArgs e)
{
PassText.BackColor = Color.Empty;
}
}
}
名前を置き換えると、すべてのウィンドウを修正する必要があるため、プロジェクト全体が壊れてしまいます。その他の方法で?たぶん異なる機能を使用していますか? – Programmer23
「交換する」必要はありません。宣言し、xButton1_Clickメソッド内の変数を使用するだけです。そうすれば、メソッドの外側には何も影響しませんが、そのメソッド内で使用される入力をクリーンアップするだけです。 –
答えに 'String'変数はどこに置かれますか? – Programmer23