我有一个显示某人信息的数据网格。我想做的是合并列(houseno,town,province,street)并将其显示为一个。我怎样才能做到这一点? 这是我的代码:
conn = New MySqlConnection
conn.ConnectionString = "server=localhost; userid=root; password=root; database=dbase"
Dim da As New MySqlDataAdapter
Dim bs As New BindingSource
Try
conn.Open()
Sql = "SELECT facultyNo AS `Faculty ID`, " & _
"firstname AS `Firstname` , " & _
"middlename AS `Middlename` , " & _
"lastname AS `Lastname` , " & _
"gender AS `Gender` , " & _
"homeadd_houseno & homeadd_brgy & homeadd_street & homeadd_town AS `Home Address` , " & _ "THIS IS WHAT I WANTED"
"tersiary_schoolname AS `School Name` , " & _
"tersiary_address AS `School's Address` , " & _
"tersiary_degree AS `Degree` , " & _
"tersiary_batch AS `Batch` , " & _
"birthdate AS `Birthdate` , " & _
"contact_mobileno AS `Mobile No.` , " & _
"contact_telno AS `Telephone No.` , " & _
"age AS `Age` , " & _
"collegeSchool AS `Tersiary` , " & _
"schoolAdd AS `School's Address` , " & _
"emailAdd AS `Email Address` , " & _
"contactno AS `Contact Number` " & _
"FROM dbase.tblfacultyinfo"
cmd = New MySqlCommand(Sql, conn)
da.SelectCommand = cmd
da.Fill(dt)
bs.DataSource = dt
DataGridView1.DataSource = bs
da.Update(dt)
conn.Close()
Catch ex As MySqlException
MsgBox(ex.Message)
Finally
conn.Dispose()
End Try
End Sub
答案 0 :(得分:0)
SQL使用'+'而非'&'对于字符串连接,请尝试...
homeadd_houseno + ' ' + homeadd_brgy + ' ' + homeadd_street + ' ' + homeadd_town AS `Home_Address`
答案 1 :(得分:0)
使用CONCAT
select concat (homeadd_houseno,', ',homeadd_brgy,', ',homeadd_street,', ',homeadd_town ) AS `Home Address`
from
dbase.tblfacultyinfo