c# - Left Join Mysql 查询结果错误

标签 c# mysql

我有一个 mysql 左连接查询。该查询运行正常。但左连接表没有获取值。请通过以下查询。我正在使用 C# 工作

void getstuinfo()
        {
            try
            {
                MySqlCommand com = new MySqlCommand("select stumaster.stuname,"+
                "stumaster.lname,"+
                "stumaster.fname,"+
                "stumaster.mname,"+
                "stumaster.fa_calty,"+
                "stumaster.sex,"+
                "castmaster.castdisp,"+
                "stumaster.castcode,"+
                "stumaster.nwscs "+
                "from stumaster "+ 
                " left join castmaster  on stumaster.castcode = castmaster.castcode "+
                " where grno = " + Convert.ToInt32(textBox1.Text).ToString(), con_db.con);
                MySqlDataReader dr1 = com.ExecuteReader();
                if (dr1.HasRows)
                {
                    while (dr1.Read())
                    {
                        textBox2.Text = (dr1[("stuname")].ToString());
                        textBox4.Text = (dr1["lname"]).ToString();
                        textBox5.Text = (dr1["fname"]).ToString();
                        textBox6.Text = (dr1["mname"]).ToString();
                        comboBox5.Text = (dr1["fa_calty"]).ToString();
                        comboBox1.Text = (dr1["castdisp"]).ToString();
                        textBox7.Text = (dr1["castcode"]).ToString();
                        textBox9.Text = (dr1["nwscs"]).ToString();
                        string wsex = (dr1["sex"]).ToString();

                        if (wsex == "M")
                        {
                            radioButton1.Checked = true;
                        }
                        else
                        {
                            radioButton2.Checked = true;
                        }
                    }
                    dr1.Close();
                }
                else
                {
                    MessageBox.Show("Not a Valid G.R.No.", " Student Information ");
                    dr1.Close();
                    textBox1.Focus();
                    return;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Date is Invalid  ");
            }
        }

最佳答案

你必须用 grno 给出表名

stumaster.grno   = conditiion

关于c# - Left Join Mysql 查询结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42969356/

相关文章:

c# - 日期时间转换 添加 5 小时

c# - List<string> 简单分组和计数?

c# - Xamarin - 自定义渲染器找不到合适的方法来覆盖

android - 无法使用 JSON 从 MySQL 检索数据并将其放入带有 Fragments 的 ListView 中

mysql - 无法在 mysql 中使用枚举

php - Highcharts 数据来自 mysql 数据库

c# - 跨 VS 2012 和 VS 2010 的 TFS 2012 工作区

c# - WPF 自定义形状列表框

mysql - CakePHP 3.x - 关联错误 - 无法将表链接在一起

java - 在hibernate查询中获取数据库名称