Home All Groups Group Topic Archive Search About

Database filepath got overrided by OpenFiledialog???

Author
2 Apr 2005 9:37 PM
Jon
Hi,

I am scratching all my hair out and really have no idea what is happening
with my program...

I have a dataset, and i used dataAdapter to fill the data. Everything works
fine until I run the OpenFileDialog, and select a txt file ( the file i
select has nothing do with the database).

When i try to update my dataset, It gives out
"System.Data.OleDb.OleDbException" because it is trying to find
MyDataBase.mdb where the path is the one i selected in the openFileDialoge!?!?

but the weird thing is my path for the oledb is constant, and more
importantly i dont see any connection between the two..

What should I do so that the openFiledialog won't affect the path of my
Database??

but still anyway, i can't see anything wrong in my code that my DB path will
get affected by the change of a openfiledialog...?

please if anyone can help.
Thank you very much in advance!

' Here is how i create the oledb connection
   ' Create OLEDB connection

Const m_OLEDB_PATH As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source= Data\MyDataBase.mdb"

Dim OleDbConn As New OleDbConnection(m_OLEDB_PATH)
            m_da = New OleDbDataAdapter
            m_da.SelectCommand = New OleDbCommand(m_str, OleDbConn)
            Dim cmd As New OleDbCommandBuilder(m_da)

            OleDbConn.Open()

            ' Fill DataTable in DataSet via DataAdapter
            m_da.Fill(m_ds, m_tbName)
            m_ds.CaseSensitive = True

            OleDbConn.Close()

Author
3 Apr 2005 1:10 AM
Ken Tucker [MVP]
Hi,

        You are not using a hard coded path.  The connection is looking for
a database at the current directory\data\mydatabase.mdb.  When you run the
open file dialog you change the current directory.

Ken
--------------------
"Jon" <J**@discussions.microsoft.com> wrote in message
news:345F31B1-12A7-4B60-999E-40526C318AC4@microsoft.com...
Hi,

I am scratching all my hair out and really have no idea what is happening
with my program...

I have a dataset, and i used dataAdapter to fill the data. Everything works
fine until I run the OpenFileDialog, and select a txt file ( the file i
select has nothing do with the database).

When i try to update my dataset, It gives out
"System.Data.OleDb.OleDbException" because it is trying to find
MyDataBase.mdb where the path is the one i selected in the
openFileDialoge!?!?

but the weird thing is my path for the oledb is constant, and more
importantly i dont see any connection between the two..

What should I do so that the openFiledialog won't affect the path of my
Database??

but still anyway, i can't see anything wrong in my code that my DB path will
get affected by the change of a openfiledialog...?

please if anyone can help.
Thank you very much in advance!

' Here is how i create the oledb connection
   ' Create OLEDB connection

Const m_OLEDB_PATH As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source= Data\MyDataBase.mdb"

Dim OleDbConn As New OleDbConnection(m_OLEDB_PATH)
            m_da = New OleDbDataAdapter
            m_da.SelectCommand = New OleDbCommand(m_str, OleDbConn)
            Dim cmd As New OleDbCommandBuilder(m_da)

            OleDbConn.Open()

            ' Fill DataTable in DataSet via DataAdapter
            m_da.Fill(m_ds, m_tbName)
            m_ds.CaseSensitive = True

            OleDbConn.Close()
Author
3 Apr 2005 2:02 AM
Stephany Young
Who's got eagle eyes today then? :)


Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:e$Zpjn%23NFHA.3828@TK2MSFTNGP10.phx.gbl...
> Hi,
>
>        You are not using a hard coded path.  The connection is looking for
> a database at the current directory\data\mydatabase.mdb.  When you run the
> open file dialog you change the current directory.
>
> Ken
> --------------------
> "Jon" <J**@discussions.microsoft.com> wrote in message
> news:345F31B1-12A7-4B60-999E-40526C318AC4@microsoft.com...
> Hi,
>
> I am scratching all my hair out and really have no idea what is happening
> with my program...
>
> I have a dataset, and i used dataAdapter to fill the data. Everything
> works
> fine until I run the OpenFileDialog, and select a txt file ( the file i
> select has nothing do with the database).
>
> When i try to update my dataset, It gives out
> "System.Data.OleDb.OleDbException" because it is trying to find
> MyDataBase.mdb where the path is the one i selected in the
> openFileDialoge!?!?
>
> but the weird thing is my path for the oledb is constant, and more
> importantly i dont see any connection between the two..
>
> What should I do so that the openFiledialog won't affect the path of my
> Database??
>
> but still anyway, i can't see anything wrong in my code that my DB path
> will
> get affected by the change of a openfiledialog...?
>
> please if anyone can help.
> Thank you very much in advance!
>
> ' Here is how i create the oledb connection
>   ' Create OLEDB connection
>
> Const m_OLEDB_PATH As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
> Source= Data\MyDataBase.mdb"
>
> Dim OleDbConn As New OleDbConnection(m_OLEDB_PATH)
>            m_da = New OleDbDataAdapter
>            m_da.SelectCommand = New OleDbCommand(m_str, OleDbConn)
>            Dim cmd As New OleDbCommandBuilder(m_da)
>
>            OleDbConn.Open()
>
>            ' Fill DataTable in DataSet via DataAdapter
>            m_da.Fill(m_ds, m_tbName)
>            m_ds.CaseSensitive = True
>
>            OleDbConn.Close()
>
>
Author
3 Apr 2005 3:34 AM
Michael C#
myFileDialog.RestoreDirectory = True

Will keep OpenFileDialog from changing the Current Directory for your app.

Show quoteHide quote
"Jon" <J**@discussions.microsoft.com> wrote in message
news:345F31B1-12A7-4B60-999E-40526C318AC4@microsoft.com...
> Hi,
>
> I am scratching all my hair out and really have no idea what is happening
> with my program...
>
> I have a dataset, and i used dataAdapter to fill the data. Everything
> works
> fine until I run the OpenFileDialog, and select a txt file ( the file i
> select has nothing do with the database).
>
> When i try to update my dataset, It gives out
> "System.Data.OleDb.OleDbException" because it is trying to find
> MyDataBase.mdb where the path is the one i selected in the
> openFileDialoge!?!?
>
> but the weird thing is my path for the oledb is constant, and more
> importantly i dont see any connection between the two..
>
> What should I do so that the openFiledialog won't affect the path of my
> Database??
>
> but still anyway, i can't see anything wrong in my code that my DB path
> will
> get affected by the change of a openfiledialog...?
>
> please if anyone can help.
> Thank you very much in advance!
>
> ' Here is how i create the oledb connection
>   ' Create OLEDB connection
>
> Const m_OLEDB_PATH As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data
> Source= Data\MyDataBase.mdb"
>
> Dim OleDbConn As New OleDbConnection(m_OLEDB_PATH)
>            m_da = New OleDbDataAdapter
>            m_da.SelectCommand = New OleDbCommand(m_str, OleDbConn)
>            Dim cmd As New OleDbCommandBuilder(m_da)
>
>            OleDbConn.Open()
>
>            ' Fill DataTable in DataSet via DataAdapter
>            m_da.Fill(m_ds, m_tbName)
>            m_ds.CaseSensitive = True
>
>            OleDbConn.Close()