这是我的登录页面,但它无法读取数据库中的行id
如何阅读登录人员的id
并使用MessageBox
向他显示值?
using System.Data.Sql;
using System.Data.SqlClient;
namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-TLOVFL6;Initial Catalog=testsqlinsert;Integrated Security=True");
SqlDataAdapter da;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
this.Hide();
f3.ShowDialog();
this.Show();
}
private void button3_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT id,username,password FROM empdata Where username=@username AND password=@password", con);
cmd.Parameters.Add("@username", textBox1.Text);
cmd.Parameters.Add("@password", textBox2.Text);
SqlDataReader dr;
dr = cmd.ExecuteReader();
int c = 0;
while (dr.Read())
{
c += 1;
}
if (c == 1)
{
Form4 f4 = new Form4();
this.Hide();
f4.ShowDialog();
this.Show();
}
else if (c > 0)
{
MessageBox.Show("duplicTE");
}
else
{
MessageBox.Show("USERNAME OR PASSWORD IS NOT CURRECT");
}
textBox1.Clear();
textBox2.Clear();
con.Close();
}
}
}
感谢您的帮助