多表操作一般情况下只使用查询操作
多表操作:as(起别名) 此时有问题 没有班级的学生(即gid为NULL)难道 不配被查询嘛?
SELECT * FROM student AS a, grade AS b WHERE a.gid = b.gid
高级多表查询:INNER JOIN 内连接 LEFT JOIN 左连接(以左表为主表查询 如果右表没有与之匹配的数据就用null来代替)
SELECT * FROM student a LEFT JOIN grade b ON a.gid = b.gid 三、登录操作
// 重置按钮:清空输入框里面的值
this.textBox1.Text = "";
this.textBox2.Text = "";
this.radioButton1.Checked = true;
this.radioButton2.Checked = false;
// 点击登录
string password = null;
if (radioButton1.Checked == true)
{
// string.Format格式化字符串
string sql = string.Format(@"SELECT password FROM student WHERE username='{0}'", textBox1.Text);
// 执行sql 返回一个结果集
MySqlDataReader res = DBhelp.executeQuery(sql);
// 一行一行 往下读
while (res.Read())
{
password = res["password"].ToString();
}
if (password.Equals(textBox2.Text))
{
MessageBox.Show("登录成功");
} else
{
MessageBox.Show("账号密码错误");
}
} else
{
string sql = string.Format(@"SELECT password FROM teacher WHERE username='{0}'", textBox1.Text);