无法从字符串中删除最后一个字符

时间:2017-11-05 02:29:03

标签: sql .net vb.net oledb

我有一个Access数据库,我正在查询employee表。新员工的姓氏后面附有一个星号(例如:Bob Smith *)。在我的查询中,我试图删除星号并将员工姓名加载到ComboBox中。但是,ComboBox保持空白。如果我在Access本身内运行查询,它会产生预期的结果。

数据库结构:

Database Structure

以下是相关代码:

Public Class frmMain

Dim data As DataSet

Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    'load data from master database
    data = New DataSet
    Dim a As New OleDbDataAdapter("SELECT LEFT(Last_Name_String, LEN(Last_Name_String)-1), First_Name_String FROM Basic_Employee_Information_Table", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &
        fileReader.ToString())
    a.Fill(data, "Employees")

    For Each item In data.Tables("Employees").Rows
        cboEmployee.Items.Add(item("Last_Name_String") & ", " & item("First_Name_String"))
    Next

End Sub

1 个答案:

答案 0 :(得分:2)

您的查询未返回任何名为" Last_Name_string"的内容。使用别名:

SELECT LEFT(Last_Name_String, LEN(Last_Name_String)-1) as Last_Name_String,
       First_Name_String