#region 页面跳转到教师管理界面 public void Teacherloging()
{
string username = this.CB_UID.Text.Trim();
string password = this.txt_password.Text.Trim();
string str = "initial catalog = StudentMS;data source = .; integrated security = true";
SqlConnection conn = new SqlConnection(str);
string sql = "select * from Tmoreinfo";
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds,"Tmoreinfo"); DataRow drv;
drv =ds.Tables["Tmoreinfo"].Rows[this.BindingContext[ds, "Tmoreinfo"].Position]; string id = drv["tmi_username"].ToString();
string pwd = drv["tmi_password"].ToString();
string category = drv["tmi_category"].ToString();
//SqlCommand cmd;
//cmd = new SqlCommand();
//cmd.CommandText = "select * from Smoreinfo where smi_username = '" + username + "' and smi_password ='" + password + "' ";
//cmd.CommandType = CommandType.Text;
//cmd.Connection = conn;
//SqlDataReader sdr;
//sdr = cmd.ExecuteReader(); if (username == "" || password == "")
{
MessageBox.Show("账号或密码不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //判断如果输入的账号或密码与数据库不匹配,返回错误信息
else if (!username.Equals(id) || !password.Equals(pwd))
{
MessageBox.Show("账号或密码错误,请核实后重新输入!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//账号密码正确,实现页面跳转
else
{
if (this.CB_chooselist.Text == "")
{
MessageBox.Show("请选择您的身份类型", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (!this.CB_chooselist.Text.Equals(category))
{
MessageBox.Show("您的身份类型有误,请重新输入", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
TeacherinfoOpreation tio = new TeacherinfoOpreation();
this.Hide();
tio.Show();
this.Close();
} }
}
catch (SqlException sqle)
{
MessageBox.Show(sqle.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conn.Close();
}
这段代码用于实现从登入界面跳转到子页面,但是问题是运行后,原本数据库的相关数据表中有多条用户记录,但是只有第一条记录可以实现登录跳转功能,输入其余的账号和密码,就会返回说账号密码错误,个人认为显然是程序仅仅读出了第一条记录,但是我不知如何解决
请各位大虾帮帮小弟的忙,谢谢
{
string username = this.CB_UID.Text.Trim();
string password = this.txt_password.Text.Trim();
string str = "initial catalog = StudentMS;data source = .; integrated security = true";
SqlConnection conn = new SqlConnection(str);
string sql = "select * from Tmoreinfo";
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
sda.Fill(ds,"Tmoreinfo"); DataRow drv;
drv =ds.Tables["Tmoreinfo"].Rows[this.BindingContext[ds, "Tmoreinfo"].Position]; string id = drv["tmi_username"].ToString();
string pwd = drv["tmi_password"].ToString();
string category = drv["tmi_category"].ToString();
//SqlCommand cmd;
//cmd = new SqlCommand();
//cmd.CommandText = "select * from Smoreinfo where smi_username = '" + username + "' and smi_password ='" + password + "' ";
//cmd.CommandType = CommandType.Text;
//cmd.Connection = conn;
//SqlDataReader sdr;
//sdr = cmd.ExecuteReader(); if (username == "" || password == "")
{
MessageBox.Show("账号或密码不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //判断如果输入的账号或密码与数据库不匹配,返回错误信息
else if (!username.Equals(id) || !password.Equals(pwd))
{
MessageBox.Show("账号或密码错误,请核实后重新输入!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//账号密码正确,实现页面跳转
else
{
if (this.CB_chooselist.Text == "")
{
MessageBox.Show("请选择您的身份类型", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (!this.CB_chooselist.Text.Equals(category))
{
MessageBox.Show("您的身份类型有误,请重新输入", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
TeacherinfoOpreation tio = new TeacherinfoOpreation();
this.Hide();
tio.Show();
this.Close();
} }
}
catch (SqlException sqle)
{
MessageBox.Show(sqle.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conn.Close();
}
这段代码用于实现从登入界面跳转到子页面,但是问题是运行后,原本数据库的相关数据表中有多条用户记录,但是只有第一条记录可以实现登录跳转功能,输入其余的账号和密码,就会返回说账号密码错误,个人认为显然是程序仅仅读出了第一条记录,但是我不知如何解决
请各位大虾帮帮小弟的忙,谢谢
DataRow drv;
drv =ds.Tables["Tmoreinfo"];