1
   

Help with Databases and C++

 
 
Reply Sat 4 Sep, 2004 10:31 am
Ok, so I want to write a program that will require the use of a database... Problem is, I have no idea how to create/link/query a database to a C++ program. I don't want to use an SQL server (unless i have to)... So can anyone give me some info or point me in the right direction? Is it best to use access or foxpro or what to create the database???

thanks.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 715 • Replies: 3
No top replies

 
stuh505
 
  1  
Reply Sat 4 Sep, 2004 01:31 pm
I'm not sure about c++, but I have done a lot of database access with C# and Access...perhaps looking over this will help

private static OdbcConnection objConnection;
private static string strConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=";

public static DataSet GetDataSet(string strQuery, string strTblName)
//PRE: strQuery is a SQL Query, strTblName is name of a table to create to put the data in
//POST: a DataSet is created and a table named strTblName is created
// containing the results of the SQL query
{
//OdbcConnection objConnection =GetDBConnection();
OdbcDataAdapter odbcAdapter1=GetDBAdapter(strQuery,objConnection);
DataSet Results = new DataSet("Results");
odbcAdapter1.Fill(Results,strTblName);
return Results;
}

private static OdbcDataAdapter GetDBAdapter(string strSQL,OdbcConnection objConnection)
//PRE: An SQL statement and a connection
//POST: returns an adapter which is used to execute the SQL query by GetDataSet
{
return (new OdbcDataAdapter(strSQL,objConnection));
}

private static OdbcConnection GetDBConnection()
//PRE: nothing
//POST: A new OdbcConnection object to the database indicated by the strConnection string.
{
return( new OdbcConnection(strConnection));
}
0 Replies
 
danload
 
  1  
Reply Sat 4 Sep, 2004 02:55 pm
If the target OS is Windows, you should call the ODBC API (Open Database Connectivity) functions from your C or C++ program.

You should find all the information browsing the Microsoft MSDN online version (http://msdn.microsoft.com/default.aspx).

Good luck!
0 Replies
 
stuh505
 
  1  
Reply Sat 4 Sep, 2004 03:05 pm
yep dan is right, and that's what I was doing in my c# example also, so there are probably some strong similarities
0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » Help with Databases and C++
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 05/19/2024 at 02:10:43