简体   繁体   English

如何使用此查询选择更多列

[英]How would I go about selecting more columns with this query

I just need to know how I would place more table columns in this query, like major ect. 我只需要知道如何在此查询中放置更多表列,例如major ect。

Thank you! 谢谢!

MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT * FROM student", conn);
            MySqlCommandBuilder sqlCmd = new MySqlCommandBuilder(adap);
            DataSet sqlSet = new DataSet();
            adap.Fill(sqlSet, "studentNumber");
            conn.Close();
            return sqlSet;

EDIT: 编辑:

I think I asked the question wrong, I dont want entries from another table..I need the following. 我想我问错了这个问题,我不想要其他表中的条目。我需要以下内容。

I have a table called student , in this table I have 4 columns, one of them being studentNumber another being major another gradePointAverage . 我有一个称为student的表,在此表中我有4列,其中一列是studentNumber另一列是major另一个是gradePointAverage How to I add these columns into the code above? 如何将这些列添加到上面的代码中?

EDIT NUMBER 2: 编辑编号2:

I know how to do the SELECT statement, I was more looking for help on this section adap.Fill(sqlSet, "studentNumber"); 我知道如何执行SELECT语句,我更多地是在此部分寻求帮助adap.Fill(sqlSet, "studentNumber"); How do I put the major column into that? 我如何将major专栏放入其中?

使用以下查询

select students.*,table2.major from student inner join table2 on student.it = table2.id

you can specify the columns names as below 您可以如下指定列名称

"SELECT studentNumber,major   FROM student"

since you have * that means select all the columns, your code will return all the table columns 由于您具有*表示选择所有列,因此您的代码将返回所有表列

您可以使用联接查询来选择更多列,但前提是下面两个表中的列名称相同时才是查询SELECT t1.column AS column1,t2.column AS column2 FROM table1 AS t1 LEFT JOIN table2 AS t2 ON t1.column = t2 。柱

I have a table called student, in this table I have 4 columns, one of them being studentNumber another being major another gradePointAverage. 我有一个称为学生的表,在此表中有4列,其中一列是StudentNumber,另一列是专业,另一个是GradePointAverage。 How to I add these columns into the code above? 如何将这些列添加到上面的代码中?

So select your columns in your query. 因此,在查询中选择列。

Change 更改

MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT * FROM student", conn);

to

MySqlDataAdapter adap = new MySqlDataAdapter(@"SELECT studentNumber, major FROM student", conn);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM