这是我的table. table patient
我希望firstname和lastname在datagridview中合并为“name”,我该怎么做?
这是我的输出My output of datagridview
我的代码……
private void frmPatient_Load(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection("server = localhost; database = nuclinic; username = root; password = ; Convert Zero Datetime=True");
string query = "select firstname, lastname from patient";
using (MySqlDataAdapter adpt = new MySqlDataAdapter(query, con))
{
DataSet dset = new DataSet();
adpt.Fill(dset);
dataGridView1.DataSource = dset.Tables[0];
}
con.Close();
}
我试过这段代码“SELECT firstname”,“lastname AS name”;
但它不起作用
解决方法:
您只需使用MySQL CONCAT函数将两列和结果连接到一列,如名称所示.您可以使用它在网格视图中显示.
select CONCAT(firstname,' ', lastname) as name, firstname, lastname from patient