Reading data from Access and save it into an array


T

TeamPhobie

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
 
Ad

Advertisements

M

Malcolm McLean

Hello,

This is my first post here an i hope i can get some help :) hope my english isn't too bad.
Hello, and welcome to comp.lang.c
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.
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.
 
J

J. Clarke

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.

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").
 
T

TeamPhobie

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 :)
 
T

TeamPhobie

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 :) 
 
T

TeamPhobie

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 :) 
 
Ad

Advertisements

T

TeamPhobie

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 :) 
 
T

TeamPhobie

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 :) 
 
B

Ben Bacarisse

TeamPhobie said:
Hey.
i googled a bit and found this code:

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>
 
D

David Brown

Oh sorry thought its for all kinds of c :/
Thanks for the helps anyway :)

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.
 
Ad

Advertisements

K

Kenny McCormack

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

Heh heh.
But it is not for languages with a letter C in their name, such as C#,

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.)
 
M

Martin Shobe

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.

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

Martin Shobe
 
D

David Brown

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.

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.
 
K

Kenny McCormack

David Brown said:
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.

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)
 
J

James Kuyper

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?

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.
 
Ad

Advertisements

J

James Kuyper

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.
 
K

Keith Thompson

James Kuyper said:
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.

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.
 
M

marvin.radke

Ye stupid to speak of line in code. I meant this line:"//-----------"
I dont understand what the two lines under this line are doing.
 
Ad

Advertisements

D

David Brown

In spite of the bias against anything MS, one can actually say that MS
'saved' Java. Until MS released their version Sun had been sitting on
Java for almost 3 years doing nothing with it. What really scared the
h*ll out of Sun was not so much the Windows extensions - it was the
fact the MS Java runtime ran circles around Sun's.

When anyone that was familar with Java, (and had an open-mind <g>)
opened up Visual Studio's J++ for the first time, there was a definite
WoW! factor compared to other tools available at the time, and an
immediate awareness "Sun's Java" was dead. Sun had absolutely no
choice.

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. :)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top