我的查询不希望在我的文本框中显示

时间:2015-05-28 10:54:52

标签: c# sql database database-connection

我做了2个查询,第一个是他一直很好地展示,第二个是几乎相同他没有显示..我从组合框中选择,他必须在文本框中显示名称,但是他在第二个文本框中显示名称1 ime后显示他第二次显示id,我不知道什么是错的

    private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
    {
        //1
            con.Open();
            cmd = new SqlCommand("SELECT a.naam FROM [dbo].activiteiten_in_reserveringen air, [dbo].activiteiten a , [dbo].reserveringen r ,[dbo].klanten k WHERE a.id = air.activiteit_id AND air.reservering_id = r.id AND k.id = r.klant_id", con);
            SqlDataReader myReader = cmd.ExecuteReader();
            string SUM;
            while (myReader.Read())
            {
                SUM = myReader.GetString(0);
                Console.WriteLine(SUM);
                tbbActiviteit.Text = SUM;

            }


            con.Close();
        //2
            con.Open();
            cmd = new SqlCommand("SELECT k.naam FROM [dbo].activiteiten_in_reserveringen air, [dbo].activiteiten a , [dbo].reserveringen r ,[dbo].klanten k WHERE a.id = air.activiteit_id AND air.reservering_id = r.id AND k.id = r.klant_id", con);
            SqlDataReader myReadera = cmd.ExecuteReader();
            string SUM2;
            while (myReadera.Read())
            {
                SUM2 = myReadera.GetString(0);
                Console.WriteLine(SUM2);
                tbbNaam.Text = SUM2;
            }


            con.Close();

    }

1 个答案:

答案 0 :(得分:0)

您在第二个查询中选择了k.naam,而此列位于表[dbo].activiteiten中,并且您在第一个查询a中选择了别名a.naam。因此,您需要在第二个查询中选择a.naam,或者将表格[dbo].activiteiten命名为k。

第二个查询应该是这样的

SELECT a.naam FROM [dbo].activiteiten_in_reserveringen air, [dbo].activiteiten a , [dbo].reserveringen r ,[dbo].klanten k WHERE a.id = air.activiteit_id AND air.reservering_id = r.id AND k.id = r.klant_id