Reading data from Access and save it into an array

Discussion in 'C Programming' started by TeamPhobie, May 25, 2014.

  1. TeamPhobie

    TeamPhobie Guest

    Hello,
    This is my first post here an i hope i can get some help :) hope my english isn't too bad.

    So here is my problem:

    I've got a local access database (.mdb) which is connected to my visual studio project.

    It got the fields teamname,goals,goalsofopponent,points.

    Now i want to save then data in this fields into arrays, but i have no idea how to do so :(



    Hope someone can help me.

    Greetings,

    Marvin Radke
     
    TeamPhobie, May 25, 2014
    #1
    1. Advertisements

  2. Hello, and welcome to comp.lang.c
    Visual Studio probably ships with a library for reading and writing to .mdb database files.

    The first thing is to find out what this library is, and link it in to your program. That's
    often the hardest part. You need to spiffy the name of the library to the linker. Then you
    need to work out how to call it. To do this, it's best to write little test programs that
    just query the database and print values out with printf(). (Beware that strings in databases
    are often not nil-terminated).
    The you need to query the mdb file for the number of records. Call malloc() to allocate
    that number of your internal data structures. Then loop through, querying the database
    and populating your array.
     
    Malcolm McLean, May 25, 2014
    #2
    1. Advertisements

  3. TeamPhobie

    J. Clarke Guest

    You've actually asked a fairly broad question. You can access the .mdb
    file directly if you can decipher the file structure (google "mdb file
    structure") or you can use one of several Microsoft libraries (google
    "ms access from c") or you can try some third party libraries.

    You may find it necessary to write some glue logic in C++/CLI with a
    wrapper callable from C (google "call c++ objects from c").
     
    J. Clarke, May 25, 2014
    #3
  4. TeamPhobie

    TeamPhobie Guest

    Hey.
    i googled a bit and found this code:

    using System.Data.OleDb;
    using System.Windows.Forms;
    using System.Data;  

    class Csharp_Access
    {
    public void Csharp_Access_Datenbank()
    {
    OleDbConnection con = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\data.mdb");
    con.Open();
    string strSQL = "SELECT * FROM Tabelle1";
    //--------------------
    OleDbCommand cmd = new OleDbCommand(strSQL, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
    MessageBox.Show(dr[0].ToString());
    }
    dr.Close();
    con.Close();
    }
    }

    I tested it and it works like it is supposed to do. I understand what it does until the line i added. Could you explain it to me?

    Thanks for every help :)
     
    TeamPhobie, May 26, 2014
    #4
  5. TeamPhobie

    TeamPhobie Guest

    Hey.
    i googled a bit and found this code:



    using System.Data.OleDb;
    using System.Windows.Forms;
    using System.Data;

    class Csharp_Access
    {
    public void Csharp_Access_Datenbank()
    {
    OleDbConnection con = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\data.mdb");
    con.Open();
    string strSQL = "SELECT * FROM Tabelle1";
    //--------------------
    OleDbCommand cmd = new OleDbCommand(strSQL, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    While(dr.Read())
    {
    MessageBox.Show(dr[0].ToString());
    }
    dr.Close();
    con.Close();
    }
    }

    I tested it and it works like it is supposed to do. KIt gives out the entrys of a column in a message.) I understand what it does until the line i added. Could you explain it to me? Thanks for every help :) 
     
    TeamPhobie, May 26, 2014
    #5
  6. TeamPhobie

    TeamPhobie Guest

    Hey.
    i googled a bit and found this code:



    using System.Data.OleDb;
    using System.Windows.Forms;
    using System.Data;

    class Csharp_Access
    {
    public void Csharp_Access_Datenbank()
    {
    OleDbConnection con = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\data.mdb");
    con.Open();
    string strSQL = "SELECT * FROM Tabelle1";
    //--------------------
    OleDbCommand cmd = new OleDbCommand(strSQL, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    While(dr.Read())
    {
    MessageBox.Show(dr[0].ToString());
    }
    dr.Close();
    con.Close();
    }
    }

    I tested it and it works like it is supposed to do. KIt gives out the entrys of a column in a message.) I understand what it does until the line i added. Could you explain it to me? Thanks for every help :) 
     
    TeamPhobie, May 26, 2014
    #6
  7. TeamPhobie

    TeamPhobie Guest

    Hey.
    i googled a bit and found this code:



    using System.Data.OleDb;
    using System.Windows.Forms;
    using System.Data;

    class Csharp_Access
    {
    public void Csharp_Access_Datenbank()
    {
    OleDbConnection con = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\data.mdb");
    con.Open();
    string strSQL = "SELECT * FROM Tabelle1";
    //--------------------
    OleDbCommand cmd = new OleDbCommand(strSQL, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    While(dr.Read())
    {
    MessageBox.Show(dr[0].ToString());
    }
    dr.Close();
    con.Close();
    }
    }

    I tested it and it works like it is supposed to do. KIt gives out the entrys of a column in a message.) I understand what it does until the line i added. Could you explain it to me? Thanks for every help :) 
     
    TeamPhobie, May 26, 2014
    #7
  8. TeamPhobie

    TeamPhobie Guest

    Hey.
    i googled a bit and found this code:



    using System.Data.OleDb;
    using System.Windows.Forms;
    using System.Data;

    class Csharp_Access
    {
    public void Csharp_Access_Datenbank()
    {
    OleDbConnection con = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\data.mdb");
    con.Open();
    string strSQL = "SELECT * FROM Tabelle1";
    //--------------------
    OleDbCommand cmd = new OleDbCommand(strSQL, con);
    OleDbDataReader dr = cmd.ExecuteReader();
    While(dr.Read())
    {
    MessageBox.Show(dr[0].ToString());
    }
    dr.Close();
    con.Close();
    }
    }

    I tested it and it works like it is supposed to do. KIt gives out the entrys of a column in a message.) I understand what it does until the line i added. Could you explain it to me? Thanks for every help :) 
     
    TeamPhobie, May 26, 2014
    #8
  9. That's C#. This is a C news group. You need to ask in a C# group. I'd
    give the name of a good one, but I don't know any. There will be,
    somewhere, a very active C# community.

    <snip>
     
    Ben Bacarisse, May 26, 2014
    #9
  10. TeamPhobie

    TeamPhobie Guest

    Oh sorry thought its for all kinds of c :/
    Thanks for the helps anyway :)
     
    TeamPhobie, May 26, 2014
    #10
  11. TeamPhobie

    David Brown Guest

    Yes, this newsgroup is for all kinds of C - we discuss ANSI, C90, C99,
    C11, etc.

    But it is not for languages with a letter C in their name, such as C#,
    or even for languages that are rough supersets of C such as C++. And we
    don't usually have much information about specific implementations, or
    specific libraries or applications.
     
    David Brown, May 26, 2014
    #11
  12. Heh heh.
    Come on now, you've really missed your best shot at snarkiness.

    You should have said

    It is not for all languages with a letter C in their name, such as Cobol,
    BASIC, or BCPL.

    --
    One of the best lines I've heard lately:

    Obama could cure cancer tomorrow, and the Republicans would be
    complaining that he had ruined the pharmaceutical business.

    (Heard on Stephanie Miller = but the sad thing is that there is an awful lot
    of direct truth in it. We've constructed an economy in which eliminating
    cancer would be a horrible disaster. There are many other such examples.)
     
    Kenny McCormack, May 26, 2014
    #12
  13. TeamPhobie

    Martin Shobe Guest

    We knew you would come along and supply it for us.

    Martin Shobe
     
    Martin Shobe, May 26, 2014
    #13
  14. TeamPhobie

    David Brown Guest

    I think there is at least /some/ justification for thinking C# is
    related to C - after all, it has curly brackets. And MS called it "C#"
    in the hope that people would think it is an alternative to C++, when in
    fact it is just the result of a childish tantrum at MS when a judge said
    they were not allowed to take someone else's language, screw it up and
    make it Windows-only, and then abuse the trademarked language name.
     
    David Brown, May 26, 2014
    #14
  15. You are, of course, correct, and your post is a sensible one.

    But in the religion of CLC, it is gospel that C# (and, likewise, C++) has
    no more to do with C than do any of the other languages that I mentioned.

    Had Kiki, for example, written your post, he would almost certainly have
    written it in the style of my (facetious) post, rather than in the sensible
    style of yours.

    P.S. Out of curiosity, could you point me towards the court case that you
    have in mind above? Thanks.

    --
    Religion is regarded by the common people as true,
    by the wise as foolish,
    and by the rulers as useful.

    (Seneca the Younger, 65 AD)
     
    Kenny McCormack, May 26, 2014
    #15
  16. TeamPhobie

    James Kuyper Guest

    It would help if you identified which line you added. I can guess, and
    my guess might be right, but I shouldn't have to guess. Putting an a
    appropriate comment on or near that line is one simple way to do that.

    It would also help if you could identify, in some way, what it is you
    don't understand - I realize that, since you don't understand it, it
    could be difficult to articulate which feature of the code is confusing
    you, but no one can really help you until you do. For instance, if the
    MessageBox.Show() line is the one that you added, the only lines that
    haven't been executed yet are dr.Close() and con.Close(). I'm unfamiliar
    with the language you're using, but dr.Close() seems to have an obvious
    and relatively simple meaning, so I suspect that there's something else
    that's confusing you. When you re-post this message in a more
    appropriate forum, you should try to identify more precisely what's
    confusing you.
     
    James Kuyper, May 26, 2014
    #16
  17. TeamPhobie

    James Kuyper Guest

    On 05/26/2014 07:26 AM, TeamPhobie wrote:

    Over a space of two minutes you sent four messages that seemed to be
    nearly identical to the one you posted yesterday. There's really no good
    reason for doing that unless they weren't identical - and if you're
    sending a correction, you should highlight whatever it is that you
    corrected.
     
    James Kuyper, May 26, 2014
    #17
  18. Web interfaces like Google Groups sometimes have a problem where a user
    can click a "Submit" button, and it doesn't clearly indicate that the
    article was actually submitted, but the button doesn't go away.
     
    Keith Thompson, May 27, 2014
    #18
  19. TeamPhobie

    Guest

    Ye stupid to speak of line in code. I meant this line:"//-----------"
    I dont understand what the two lines under this line are doing.
     
    , May 27, 2014
    #19
  20. TeamPhobie

    David Brown Guest

    That is an interesting viewpoint - thanks. This shows the benefits of
    competition - but also that the end users only benefit when the
    competitors play fair.

    (And while I do have a certain dislike for MS, I can grudgingly accept
    that they do /some/ things well and have done a few positive things for
    the industry. :)
     
    David Brown, May 27, 2014
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.