Thread: DataSource problem with C#

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    11

    DataSource problem with C#

    Hello again everyone. I am using the OleDb Database Provider and I am reading in csv and dBase database files. I noticed that when the datasource is something like C:\DB\, it works fine and I can read in the data, however if the datasource has a space in it like C:\D B\, it is not able to read in the data from the file. I was wondering if anyone knew if there was a way to fix that or not.

    Thanks,
    The Major Rager

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Double quotes?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    11
    Hi, thanks for replying, I was wondering if you could give me an example of where to put the double quotes.

    Thanks,
    The Major Rager.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I have no idea - I've never used C# - but in DOS:
    Code:
    C:\>cd Program Files
    Too many arguments
    C:\>cd "Program Files"
    
    C:\Program Files>
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    11
    Well I went into the debugger, it does connect to the correct datasouce, it does show the datasource as C:\D B\, but when it hits the dataReader, it seems to throw an exception. When I manually go into the directory and change the directory to C:\DB, it works.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay, so let's see the code. If it's something like this:
    Code:
    get_something("C:\D B", &what);
    then just change it to
    Code:
    get_something("\"C:\D B\"", &what);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    11
    Hi Thanks again for taking the time to reply.

    The connection string looks like this.

    Code:
    "C:\D B\"
    my program is dynamic, so when I go in and just change the directory name to C:\DB
    my code looks like this

    Code:
    "C:\DB\"
    and it is able to read it in fine.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Change it to
    Code:
    "\"C:\D B\""
    and see what happens.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    11
    the connection string looked like this in the debugger
    Code:
    "\C:\D B\"
    and it wasn't even able to connect. When I tried to open the connection
    it failed.

    It actually connects with the original as
    Code:
    C:\D B\
    however, when it gets to the dataReader, it fails for some odd reason.

  10. #10
    Registered User
    Join Date
    Aug 2005
    Posts
    11
    Hey, thanks a lot, I got it to work now. My Select statement was the problem, i just needed to reference the entire file name instead of the datasource with the file name. So I got it, thanks a lot though!

    Sincerely,
    The Major Rager

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM