Reputation: 229
is it possible to display the two database column in one row column in listview in vb.net using mysql.data.mysqlclient?
Listview: where in database:
--------------- *Firstname: John
| Full Name | *Lastname: Smith
|_____________|
| |
| John Smith |
|_____________|
here's my code:
For i = 0 To table.Rows.Count - 1
With lvlistview
.Items.Add(table.Rows(i)("dte"))
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("tran_no"))
.Add(table.Rows(i)("comp_type"))
.Add(table.Rows(i)("status"))
.Add(table.Rows(i)("sys_name"))
.Add(table.Rows(i)("mod_name"))
.Add(table.Rows(i)("err_desc"))
.Add(table.Rows(i)("trigg"))
.Add(table.Rows(i)("fname" . "lname")) **How i gonna combine this two database column in only one listview column**
End With
End With
Next
Upvotes: 2
Views: 1335
Reputation: 43743
You simply need to concatenate the values from the two DB columns together. If you were using data-binding, the simplest solution would be to alter your SQL command so that the values are concatenated by the DB engine and returned to you as a single column. However, since you are adding the items yourself, you can, alternatively, just concatenate the two columns in your code before adding the item to the ListView
, for instance:
With .Items(.Items.Count - 1).SubItems
.Add(table.Rows(i)("tran_no"))
.Add(table.Rows(i)("comp_type"))
.Add(table.Rows(i)("status"))
.Add(table.Rows(i)("sys_name"))
.Add(table.Rows(i)("mod_name"))
.Add(table.Rows(i)("err_desc"))
.Add(table.Rows(i)("trigg"))
.Add(table.Rows(i)("fname") & " " & table.Rows(i)("lname"))
End With
The &
character is the standard string-concatenation operator in VB.NET. You can also use the +
operator, but you have to be more careful of your type casting when you use the +
operator with strings. Since the &
operator is a little safer and it's slightly more self-documenting, it's typically the preferred operator for strings.
For more complicated concatenations, you may also want to consider using String.Join
, String.Format
or the StringBuilder
class.
Upvotes: 1