Results 1 to 14 of 14

Thread: [RESOLVED] [2008] Space in mdb table column

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Resolved [RESOLVED] [2008] Space in mdb table column

    I have a space in one of my columns in my database that cannot be changed (it causes issues with another app that works with the database).

    I've tried "[Set ID]" and "'Set ID'" and neither have worked.

    What's the proper way of dealing with a column name with spaces?

    Code:
                If CStr(nextRow("fname")) = CStr(currentRow("fname")) AndAlso _
                   CInt(nextRow("Set ID")) = CInt(currentRow("Set ID")) Then
    Last edited by rhijaen; Oct 2nd, 2008 at 04:33 PM.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2008] Space in mdb table column

    I am not sure since it is a long time I didn’t use mbd but I remember the column names should not have space. Why don’t you delete the space and try?

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Space in mdb table column

    Renaming the table in microsoft access causes an issue with another app that uses the database.

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2008] Space in mdb table column

    I am not sure about that but one last thing I would sagest is instead of space try it with "_".

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Space in mdb table column

    Quote Originally Posted by VBDT
    I am not sure about that but one last thing I would sagest is instead of space try it with "_".
    Nope, didn't work

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] Space in mdb table column

    What is NextRow and CurrentRow?

    When referencing field names from the client end, as long as it has quotes around it, it should be fine.... however, in the SQL it needs to have [] around it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Space in mdb table column

    The error I get is: Column 'Set ID' does not belong to table .

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            dt = New DataTable
    
            OpenFileDialog1.Filter = "mdb files(*.mdb)|*.mdb"
    
            OpenFileDialog1.ShowDialog()
    
            con.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & OpenFileDialog1.FileName
            con.Open()
            sql = "SELECT * FROM Files ORDER BY fname, fsize DESC"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(dt)
            con.Close()
    
            Dim currentRow As DataRow
            Dim nextRow As DataRow
            Dim rows As DataRowCollection = dt.Rows
            Dim cb As New OleDb.OleDbCommandBuilder(da)
    
            For index As Integer = 0 To rows.Count - 2
                currentRow = rows(index)
                nextRow = rows(index + 1)
    
                If CStr(nextRow("fname")) = CStr(currentRow("fname")) AndAlso _
                   CInt(nextRow("Set ID")) = CInt(currentRow("Set ID")) Then
                    RichTextBox1.Text = RichTextBox1.Text & vbCrLf & CInt(currentRow("Set ID"))
                    RichTextBox1.Text = RichTextBox1.Text & vbCrLf & CInt(nextRow("Set ID"))
                    RichTextBox2.Text = RichTextBox2.Text & vbCrLf & CStr(currentRow("fname"))
                    RichTextBox2.Text = RichTextBox2.Text & vbCrLf & CStr(nextRow("fname"))
                    RichTextBox3.Text = RichTextBox3.Text & vbCrLf & CInt(currentRow("fsize"))
                    RichTextBox3.Text = RichTextBox3.Text & vbCrLf & CInt(nextRow("fsize"))
                    currentRow.Delete()
                End If
            Next
    
        End Sub

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] Space in mdb table column

    Just for kicks... try this.... change your query....
    Code:
    sql = "SELECT * FROM Files ORDER BY fname, fsize DESC"
    Change it to this:
    Code:
    sql = "SELECT [Set ID] As SetID, fsize, fname, ....  FROM Files ORDER BY fname, fsize DESC"
    Now you should be able to reference it suing the ailias SetID and not have to worry about the space.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Space in mdb table column

    You can also run a simple loop to debug.write the columns' names in your datatable. That will let you see if you actually has a column "Set ID" in the table, and you can go from there to fix it.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Space in mdb table column

    Quote Originally Posted by techgnome
    Just for kicks... try this.... change your query....
    Code:
    sql = "SELECT * FROM Files ORDER BY fname, fsize DESC"
    Change it to this:
    Code:
    sql = "SELECT [Set ID] As SetID, fsize, fname, ....  FROM Files ORDER BY fname, fsize DESC"
    Now you should be able to reference it suing the ailias SetID and not have to worry about the space.

    -tg
    Nope, didn't work.

    You can also run a simple loop to debug.write the columns' names in your datatable. That will let you see if you actually has a column "Set ID" in the table, and you can go from there to fix it.
    How would I do this? I know Filename wasn't the real column, it was fname..found that out the hard way. So maybe "Set ID" isn't really a column?

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] Space in mdb table column

    k, if that didn't work, then there's something else going on that you aren't telling us. Can you post a screenshot of the code, with the error message?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Space in mdb table column

    To find out what the column names are in your datatable after you have filled it, just do this:
    Code:
    For i as integer = 0 To dt.Columns.Count - 1
        Debug.WriteLine("Column" & i & " name: " & dt.Columns(i).ColumnName())
    Next
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2008] Space in mdb table column

    Quote Originally Posted by rhijaen
    I know Filename wasn't the real column, it was fname..found that out the hard way. So maybe "Set ID" isn't really a column?
    This is why SELECT * aren't a good idea sometimes.... so... you're not even sure WHAT columns you ARE getting? If this is the case, in the amount of time this has gone around, you probably could have opened the database, looked at the table, and see what the fields names are. Or ask the table owner.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Space in mdb table column

    Quote Originally Posted by stanav
    To find out what the column names are in your datatable after you have filled it, just do this:
    Code:
    For i as integer = 0 To dt.Columns.Count - 1
        Debug.WriteLine("Column" & i & " name: " & dt.Columns(i).ColumnName())
    Next
    Thanks for this. The column name was actually SID. Even though when I open the mdb in access, the column name is "Set ID".

    All fixed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width