|
-
Sep 29th, 2007, 07:03 PM
#1
Thread Starter
Frenzied Member
[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?
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
If you find my thread helpful, please remember to rate me 
-
Sep 29th, 2007, 07:13 PM
#2
Re: Help! Spaces in Access Fieldnames
You just answered your own question:
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.
-
Sep 29th, 2007, 07:16 PM
#3
Thread Starter
Frenzied Member
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?
If you find my thread helpful, please remember to rate me 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|