Click here to Skip to main content
15,909,503 members
Home / Discussions / C#
   

C#

 
QuestionProblem set parameter value in Crystal report Pin
hieunts21-Sep-06 19:31
hieunts21-Sep-06 19:31 
QuestionReg: Webservies projects Pin
guru_41821-Sep-06 18:44
guru_41821-Sep-06 18:44 
AnswerRe: Reg: Webservies projects Pin
Christian Graus21-Sep-06 18:49
protectorChristian Graus21-Sep-06 18:49 
AnswerRe: Reg: Webservies projects Pin
guru_41821-Sep-06 18:57
guru_41821-Sep-06 18:57 
QuestionRemoting problems with ArrayList return Pin
drinkingbird21-Sep-06 15:25
drinkingbird21-Sep-06 15:25 
AnswerRe: Remoting problems with ArrayList return Pin
Dave Kreskowiak21-Sep-06 15:58
mveDave Kreskowiak21-Sep-06 15:58 
GeneralRe: Remoting problems with ArrayList return Pin
drinkingbird21-Sep-06 16:14
drinkingbird21-Sep-06 16:14 
QuestionProblem connecting to an Access database Pin
TheBlindWatchmaker21-Sep-06 13:17
TheBlindWatchmaker21-Sep-06 13:17 
Greetings!

I'm trying to connect to a database and read certain fields from it. I'm unable to read any fields from it and would appreciate your help debugging/fixing the problem.

Here is what I have:

1. A file that acts has the database interface code:

<br />
 public class AppDatabaseInterface<br />
    {<br />
<br />
        // Directory names<br />
        private string m_cstrDefaultdbDir = "C:\\";<br />
<br />
        // File names<br />
        private const string m_cstrDBFileName = "DefaultDatabase.mdb";<br />
<br />
        private System.Data.OleDb.OleDbConnection m_dbConn;<br />
<br />
        public AppDatabaseInterface()<br />
        {<br />
            // Determine the App Root directory when this object is constructed<br />
            System.Reflection.Assembly assm =<br />
                System.Reflection.Assembly.GetAssembly(System.Type.GetType("AppDatabase.AppDatabaseInterface"));<br />
            m_cstrDefaultdbDir = System.IO.Path.GetDirectoryName(assm.CodeBase.ToString());<br />
            m_cstrDefaultdbDir = m_cstrDefaultdbDir.Remove(0, 6);	// Removes the leading file:\ header from the path.<br />
<br />
            OpenDatabase();<br />
        }<br />
<br />
<br />
        private void OpenDatabase()<br />
        {<br />
            lock (this)<br />
            {<br />
                // If the database connection hasn't been initialized, create it.  <br />
                // If it exists and is currently connected, close the connection<br />
                // as we are about to establish a new connection.<br />
                if (m_dbConn == null)<br />
                {<br />
                    m_dbConn = new OleDbConnection();<br />
                }<br />
                else<br />
                {<br />
                    if (m_dbConn.State != ConnectionState.Closed)<br />
                    {<br />
                        m_dbConn.Close();<br />
                    }<br />
                }<br />
<br />
                // Create the new connection string and try and attach to the new database.<br />
                try<br />
                {<br />
                    m_dbConn.ConnectionString = string.Format(<br />
                         @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}\{1};",<br />
                         m_cstrDefaultdbDir, m_cstrDBFileName);<br />
                }<br />
                catch<br />
                {<br />
                    Console.WriteLine("Could not open database");<br />
                }<br />
                m_dbConn.Open();<br />
<br />
            }<br />
        }<br />


2. The actual UI form

<br />
public partial class frmAppDatabase: Form<br />
    {<br />
        AppDatabaseInterface m_database;<br />
<br />
        public frmSpeakerDatabase()<br />
        {<br />
            InitializeComponent();<br />
<br />
            m_database = new AppDatabaseInterface();<br />
<br />
            string[] strSpeakerMakes = m_database.Makes;<br />
<br />
            for (int i = 0; i < strSpeakerMakes.Length; i++)<br />
            {<br />
                cbSpeakerMakes.Items.Add(strSpeakerMakes[i]);<br />
            }<br />
      }<br />


What I want this portion of the code to do is to fill in the combobox with the various items from the specified field in the database. However, I see nothing.

The Access file is in the \bin\debug directory of the project.

Could you please advice me as to what is wrong?

Thanks!
AnswerRe: Problem connecting to an Access database Pin
Guffa21-Sep-06 20:53
Guffa21-Sep-06 20:53 
GeneralRe: Problem connecting to an Access database Pin
TheBlindWatchmaker22-Sep-06 5:15
TheBlindWatchmaker22-Sep-06 5:15 
GeneralRe: Problem connecting to an Access database Pin
Guffa22-Sep-06 7:29
Guffa22-Sep-06 7:29 
GeneralRe: Problem connecting to an Access database Pin
TheBlindWatchmaker22-Sep-06 7:53
TheBlindWatchmaker22-Sep-06 7:53 
GeneralRe: Problem connecting to an Access database Pin
Guffa22-Sep-06 9:39
Guffa22-Sep-06 9:39 
GeneralRe: Problem connecting to an Access database Pin
TheBlindWatchmaker22-Sep-06 9:53
TheBlindWatchmaker22-Sep-06 9:53 
AnswerRe: Problem connecting to an Access database Pin
Guffa22-Sep-06 10:37
Guffa22-Sep-06 10:37 
QuestionPathTooLongException, Work around? [modified] Pin
James_12321-Sep-06 12:34
James_12321-Sep-06 12:34 
QuestionVS2005: Unsafe mode in web service? Pin
Goalie3521-Sep-06 11:24
Goalie3521-Sep-06 11:24 
QuestionString with escaped squences... Pin
e-laj21-Sep-06 11:22
e-laj21-Sep-06 11:22 
AnswerRe: String with escaped squences... Pin
Alaric_21-Sep-06 11:41
professionalAlaric_21-Sep-06 11:41 
AnswerRe: String with escaped squences... Pin
Christian Graus21-Sep-06 11:45
protectorChristian Graus21-Sep-06 11:45 
AnswerRe: String with escaped squences... Pin
Alaric_21-Sep-06 11:49
professionalAlaric_21-Sep-06 11:49 
AnswerRe: String with escaped squences... Pin
AndriyZZ21-Sep-06 12:15
AndriyZZ21-Sep-06 12:15 
AnswerMore Details: String with escaped sequences... Pin
e-laj21-Sep-06 13:03
e-laj21-Sep-06 13:03 
GeneralRe: More Details: String with escaped sequences... Pin
Christian Graus21-Sep-06 15:27
protectorChristian Graus21-Sep-06 15:27 
GeneralRe: More Details: String with escaped sequences... Pin
e-laj21-Sep-06 16:33
e-laj21-Sep-06 16:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.