[RESOLVED] Help! Spaces in Access Fieldnames
Hi there,
I understand that one should never put spaces in fieldnames or table tables in access if using VB.Net to access them.
However, this database was not created by me and I would like to connect and manipulate the data. Please advice. Is it not possible at all? What about Square brackets? :confused:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim strSQL As String
Dim data_Dataset As New DataSet
Dim data_adapter As OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim i As Integer
strSQL = "SELECT ["
For i = 0 To Me.lstFields.SelectedIndices.Count - 1
strSQL &= Me.lstFields.Items(Me.lstFields.SelectedIndices(i)) & ","
Next
strSQL = strSQL.TrimEnd(",")
strSQL += "] FROM " & Me.lstTables.SelectedItem.ToString
MsgBox(strSQL)
' Create the SqlDataAdapter.
data_adapter = New OleDb.OleDbDataAdapter(strSQL, gConnectionString)
data_adapter.Fill(dt)
Me.DataGridView1.DataSource = dt
data_adapter.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Data Load Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
Re: Help! Spaces in Access Fieldnames
You just answered your own question:
Quote:
What about Square brackets?
You have to put brackets around each individual column name though, not the whole column list. This:
Code:
SELECT [Column1, Column2, Column3] FROM Table1
is illegal. This:
Code:
SELECT [Column1], [Column2], [Column3] FROM Table1
is correct.
Re: Help! Spaces in Access Fieldnames
Ahhhh i've resolved my own problem.
Just put square brackets on each of the field. Also need some information on the best way to format SQL statements?