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





Reply With Quote