Thread: Need help with Manipulating an MSSQL/Sybase database in C/C++

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    1

    Need help with Manipulating an MSSQL/Sybase database in C/C++

    Ok I've searched through the FAQ, even though I thought this might be beyond the scope of that, I've done a Search, and could not find what I am looking for, so I am posting it here.

    Here is my project:

    Take information from 3 different Excel CSV files, and either update, insert or delete based on comparisons between the files and the database.

    Basically a one way Sync between the CSV files and the Database.

    The app will need to be used on both Sybase and MSSQL, so my best guess (considering I've never even thought about having a thought about changing a database via C/C++) would be that I have to use ODBC to interact with the databases.

    I am also developing this as a Win32 Console application because the whole idea of event driven programing escapes me. I just can't grasp the concept.

    Ok now to my questions:

    1. How do I connect to either Database through ODBC? Are there any funcions included in my .libs or do I need to write my own functions and can you offer some help or direction here?

    2. Any help with the functions needed to Insert, Update, Select, or Delete record from the database, would be VERY much appreciated.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I suggest you use ODBC, this way it doesn't matter what DB system is on the receiving end of your commands

    If you use VC/MFC, use the CDatabase/CRecordset classes.

    As communication with any DB system includes SQL, t might help to print out the neccessary SQL statements first and testing them with test data by hand on your DB system. Then implement them with the given classes.

    PHP Code:
        try
        {

            
    CDatabase    db;

            
    db.Open"USR=scott;PWD=tiger;DSN=test" );

            
    CRecordset    rs(&db);

            
    CString        strField;
            
    CString        strSQL;
            
    int          field_x 3445;

            
    strSQL.Format"SELECT * FROM TABLE_X WHERE FIELD_X = %d"field_x );
                
            
    rs.OpenCRecordset::forwardOnlystrSQL ); 

            while( ! 
    rs.IsEOF() ) 
            {
                
    rs.GetFieldValue( (short)0strField );
                
                
    //do smth with field
            
    }

            
    rs.Close();
        
        }
        catch( 
    CException)
        {
            
    // do smth with e 
        

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. literature database: help with planning
    By officedog in forum C++ Programming
    Replies: 1
    Last Post: 01-23-2009, 12:34 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. Developing database management software
    By jdm in forum C++ Programming
    Replies: 4
    Last Post: 06-15-2004, 04:06 PM
  5. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM