473,378 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

'System.Data.OleDb.OleDbException' when creating a new DataSet..

It's still not working - is still looking for the Database in the same
folder as the photo just added.

But i've realised something... bear with me here! :)

The basics of the way my photo album works is as follows:

- A database containing photo_id (as a primary key), location
(location of photo on disk), caption etc are contained in a table in a
Database (photoDB.mdb) in the Debug folder of the project
- User opens the Photo Album program
- The Browse Photos form opens... in which photo id's are loaded from
a database into a ListBox
- When you select a photo id from the ListBox, it will get the file
location for that appropriate photo_id from the database and load it
into a picture box opposite the ListBox
- I use the same connection settings (to the database) for everything
- when the form loads, when the user selects a new photo id, when a
user deletes a photo... all works fine!
- But then clicking to open the Add Photo form then, i get the
problem!

I tried using the connection setting i've been using all along and it
looks for the Database in the same location (folder) as the photo i'm
adding. Tried using different form of connection settings /
suggestions i've been getting and they all end up the same: looking
for the database in the folder as the photo i'm adding.

However, if i skip the form involving Browsing The Photos, selecting
photos etc. and just go straight to the form to Add a new Photo.. that
connection setting works successfully and all is fine.

It's on when i load the Browsing Photo form.. and then try and open
the Add New Photo form that i get a problem.

Very long, detailed and confusing problem, i know!

By the way, i am closing the connection to the Database each time i
use it.

Any suggestions why the problem doesn't occur if i go straight to the
Add Photo form (bypassing the Browsing Photos form)? Would it be
because i'm re-using the same connection settings, variable names
(etc.) even though i'm closing the database after each method.

The connection string (that i'm re-using) is below:

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=photoDB.MDB";
string strSQL = "SELECT * FROM photos" ;
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbDataAdapter myCmd = new OleDbDataAdapter( strSQL, myConn );
myConn.Open();

DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "categories" );
DataTable dtAddTable = dtSet.Tables[0];

Then after that, i take the appropriate action (loading to a ListBox /
ComboBox) and close the connection to the database.

Any suggestions as to where i might be going wrong would be much
appreciated!

Thanks for all the help, Brian.
Nov 16 '05 #1
1 3007
Brian,

I think that I understand now! :-)

Instead of using the connection string:

Data Source=photoDB.MDB

You should get the path of the executable and append it to the Data Source
(this is slightly different than the code I gave you before…I didn’t know
that you were changing the environment path with an open dialog (or similar
control))

"...Data Source=" +
System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly().Location) + @"\ photoDB.MDB ";

What I would suggest is that you create a variable (or property) in your
code that will store the connection string. This will provide ease of use in
your code and you will always retain the same location no matter what happens.

I hope this helps!
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: silesius | last post by:
I've been using VS 2003 to develop a webapplication using C#. Today I exported the application to a remote webserver I begun experiencing problems. It's a simple application that retrieves some...
1
by: Brian | last post by:
Hello. Am getting an error message here at the line: DataSet dtSet = new DataSet(); Error is: "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll" ...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
1
by: Roger Twomey | last post by:
I have a form that allows a user to upload a microsoft Excel Spreadsheet. (I am testing with one created in Excel 2000) The spreadsheet is uploaded correctly. It is then supposed to be read...
0
by: silesius | last post by:
I've been using VS.NET 2003 to develop a webapplication using C#. Today I exported the application to another webserver I begun experiencing problems. It's a simple application that retrieves...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
6
by: Learner | last post by:
Hi there, I am trying to access the access database sitting at OleDbConnection oleConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Microsoft Visual...
0
by: John G | last post by:
I have been using Oracle Helper to connect to my oracle 9i Db. When excute text it works fine, but when I try to execute a store procedure I get the following error message. I searched...
2
by: psychomad | last post by:
Please, can someone help me out to solve this error, i've been searching throughout my codes and yet i didnt succeed in finding the error!!!! The Error is: Server Error in '/' Application....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.