我有我提取到csv的数据并读取了数据并显示到gridview。如果列包含一个单词,则显示数据,但是当列包含两个单词时,则不显示数据,代码中的示例列之一为“简短说明”。下面是我的代码
Dim fi As New FileInfo("C:\NotBackedUp\TSD_Trove\OutageDashboard DB\exeloutage.csv")
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim conn As New OleDbConnection(connectionString)
conn.Open()
'the SELECT statement is important here,
'and requires some formatting to pull dates and deal with headers with spaces.
Dim cmdSelect As New OleDbCommand("SELECT Begin, Number, Message, Short description FROM " & fi.Name, conn)
Dim adapter1 As New OleDbDataAdapter
adapter1.SelectCommand = cmdSelect
Dim ds As New DataSet
adapter1.Fill(ds, "DATA")
Outage_DashBoard.Gridview_OutageDashboard.DataSource = ds.Tables(0).DefaultView
conn.Close()
答案 0 :(得分:0)
SQL解析器无法确定“简短描述”是单个标识符。您应避免在列名和其他标识符中使用空格和其他特殊字符,例如使用Names,Highscore
Mel,8
Jack,5
David,3
Peter,6
Maria,5
Ryan,9
,但是,如果您坚持这样做,则必须在SQL代码中转义它们。在使用Jet OLE DB提供程序以及其他各种情况下,这意味着使用方括号,即ShortDescription
。