私はこのコードを持っており、ユーザー名とパスワードを含むcsvファイルを使用したいと考えています。私は設定されたユーザー名を使用したいのではなく、列1のCSVファイルのユーザー名と列2のパスワードを使用したい。 誰かが簡単な2つのテキストボックスと読み取り可能なボタン入力した値をcsvファイルと照合します。C#フォームコードヘルプ - CSVファイルを使用
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string user, password;
user = textBox1.Text;
password = textBox2.Text;
if ((user == "admin") && (password == "1234567"))
{
//then show form2
this.Hide();
var form2 = new Form2();
form2.Closed += (s, args) => this.Close();
form2.Show();
}
else
{
//if username and password is incorrect show this message box
MessageBox.Show("Username or Password Invalid");
}
}
private void button2_Click(object sender, EventArgs e)
{
}
検索は、もちろん私は( 'StreamReader')を使用してファイルを読むのが好き – Steve
このアプローチにはセキュリティが[存在しないため、これは単なるエクササイズであると思いますseparator_で文字列を_split https://msdn.microsoft.com/en-us/library/system.io.streamreader.readline(v=vs.110).aspx]あなたの場合は、[読み込まれた行を "、"](https ://msdn.microsoft.com/en-us/library/tabh47cf(v = vs.110).aspx) 'file = new StreamReader(folder + filName); while(line = file.ReadLine())!= null){foreach(line.Split( '、')の文字列inputOnFile){fileContent.Add(inputOnFile);} }} file.Close(); ' –