在VB 2010中,我尝试在不修改现有MySQL表的情况下在ProperCase中显示DisplayMember。
我的代码片段如下所示:
Dim sql0 As String = "SELECT business, customer_id FROM customers WHERE cab = '1'"
Dim data0 As New MySqlDataAdapter(sql0, main.conn)
Dim ds0 As New DataSet
ds0.Clear()
data0.Fill(ds0, "customers")
cmb_company.DataSource = ds0
cmb_company.DisplayMember = "customers.business"
cmb_company.ValueMember = "customers.customer_id"
我尝试过这样的事情:
cmb_company.DisplayMember = StrConv("customers.business_name", VbStrConv.ProperCase)
但这只会更改引号中部件的大小写,而不会更改实际返回的值。我也试过像这样查询MySQL:
"SELECT UPPER(business), customer_id FROM customers WHERE cab = '1'"
但这未能归还"业务"字段..
我喜欢它,如果我的组合框有适当的情况而不会改变一切。
我感谢任何建议!
答案 0 :(得分:0)
使用第二个,但使用如下别名:
"SELECT UPPER(business) AS Business, customer_id FROM customers WHERE cab = '1'"
MySQL documentation:
可以使用AS alias_name为select_expr指定别名。别名是 用作表达式的列名,可以在GROUP BY中使用, ORDER BY或HAVING子句。例如:
SELECT CONCAT(last_name,',',first_name)AS full_name FROM mytable ORDER BY full_name;
答案 1 :(得分:0)
使用while循环来实现这一点似乎有点愚蠢,尤其是在使用适配器填充表之后。我想我可以跳过.fill并通过循环手动添加项目,同时ProperCasing它们。无论如何,这是我的代码:
Dim sql1 As String = "SELECT * FROM table"
Dim data1 As New MySqlDataAdapter(sql1, main.conn)
Dim ds1 As New DataSet
ds1.Clear()
data1.Fill(ds1, "table")
cmb_buyout.DataSource = ds1
Dim i As Integer = 0
While i < ds1.Tables(0).Rows.Count
Dim name As String = StrConv(ds1.Tables(0).Rows(i).Item(1).ToString, VbStrConv.ProperCase)
ds1.Tables(0).Rows(i).Item(1) = name
i += 1
End While
cmb_buyout.DisplayMember = "table.buyoutType"
cmb_buyout.ValueMember = "table.id"
对于任何想要完成此任务的人来说,只更改数据库中条目的大小写可能更简单。我可能最终会这样做!