这是我的表。 table patient
我想将名字和姓氏合并为" name"在datagridview中,我该怎么做?
这是我的输出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"
;
但它不起作用
答案 0 :(得分:2)
您只需使用MySQL CONCAT函数将两列和结果连接成一列,如名称所示。您可以使用它在网格视图中显示。
select CONCAT(firstname,' ', lastname) as name, firstname, lastname from patient
答案 1 :(得分:2)
替换
string query = "select firstname, lastname from patient";
使用此
string query = "select CONCAT(firstname," ",lastname) as FullName from Patient";
Concat功能将两个名称与空间分类
结合使用AS FullName(列名称)返回列名
答案 2 :(得分:0)
试试这个:
var hashPart = encodeURIComponent(btoa(JSON.stringify(obj)));
var url = 'http://my.website#/searchPage/' + hashPart;
// Decode the uri first
var decodedObj = JSON.parse(atob(decodeURIComponent(hashPart)));
希望这有帮助。