2 개의 폼이 있습니다. 첫 번째 폼에는 사용자 이름, 암호 상자 및 로그인 버튼이 있습니다. 로그인 버튼을 클릭하면 PostgreSQL의 사용자 이름 암호가 비교됩니다. C# 및 PostgresSQL 연결 방법
private void button1_Click(object sender, EventArgs e)
{
bool blnfound = false;
NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=admin123;Database=Login");
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM login WHERE name='" + tb1.Text + "' and password = '" + tb2.Text + "'",conn);
NpgsqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
blnfound = true;
Form2 f5 = new Form2();
f5.Show();
this.Hide();
}
if (blnfound == false)
{
MessageBox.Show("Name or password is incorrect", "Message Box", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
dr.Close();
conn.Close();
}
그래서이 문제 좀 도와주십시오 하지만이 줄
NpgsqlDataReader dr = cmd.ExecuteReader(); [ ERROR: 42P01: relation "login" does not exist ]
에 오류가 발생했습니다이 내 코드입니다.
올바른 데이터베이스에 연결하고 있는지 확인하고, 로그인을 큰 따옴표로 묶으십시오. 그러면 쿼리는 'Select * From "로그인"..... "이되어야합니다. – Habib
글쎄, 당신은 테이블을 가지고 있습니까? 귀하의 데이터베이스에서 '로그인'이라고? –