QUOTE(PsychoCoder @ 22 Apr, 2008 - 09:42 PM)

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Post your code like this:

Thanks

hi sir
CODE
// database.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include "database.h"
class Database
{
public:
//CnnPtr m_Cnn;
ADODB::_ConnectionPtr m_Con;
Database();
~ Database();
bool Open(char* UserName, char* Pwd, char* CnnStr/*, char* ErrStr = NULL*/);
//RecPtr Execute(char* CmdStr);
ADODB::_RecordsetPtr Execute(char* CmdStr);
bool Close();
};
Database::Database()
{
m_Con=NULL;
}
bool Database::Open(char* UserName, char* Pwd, char* CnnStr)
{
HRESULT hr;
try
{
//if(m_Con==NULL)
// return 0;
//INITIALIZE COM
CoInitialize(NULL);
hr = m_Con.CreateInstance(__uuidof( ADODB::Connection ) );
m_Con->Open(CnnStr, UserName, Pwd, NULL);
}
catch(_com_error &e)
{
// Handle errors
return 0;
}
return 1;
}
//RecPtr Database::Execute(char* CmdStr)
ADODB::_RecordsetPtr Database::Execute(char* CmdStr)
{
try
{
if(m_Con==NULL)
return NULL;
return m_Con->Execute(CmdStr,NULL,1);
}
catch(_com_error &e)
{
// Handle errors
return NULL;
}
}
bool Database::Close()
{
//is there any established connection?
//if no, return 0
HRESULT hr;
if (m_Con==NULL)
return 0;
//if any, close that connection
try
{
m_Con->Close();
m_Con=NULL;
}
catch(_com_error &e)
{
// Handle errors
return 0;
}
return hr==S_OK;
}
Database::~Database()
{
try
{
//close connection, if not yet closed
if (m_Con)
{
m_Con->Close();
m_Con=NULL;
}
}
catch(_com_error &e)
{
// Handle errors
}
}
int main(int argc, char* argv[])
{
long noOfFields = 0;
int nIndex = 0;
char csTemp[1024] = {0, };
VARIANT varData, varValue;
//CREATE THE DB VARIABLE
Database VyomaDB;
//CREATE THE RECORDSET VARIABLE
ADODB::_RecordsetPtr VyomaRecordset = NULL;
//OPEN THE DB
if( VyomaDB.Open("", "", "Provider=MSDASQL.1;Persist Security Info=True;DSN=testMDB") )
{
//DB OPENED
printf("DB Opened");
}
else
{
printf("Sorry, DB could not be opened!! Try some other conenction String");
}
VyomaDB.Open("", "", "Provider=MSDASQL.1;Persist Security Info=True;DSN=testMDB");
VyomaRecordset = VyomaDB.Execute("select * from emp_table");
if(VyomaRecordset == NULL)
return -1;
VyomaRecordset->Fields->get_Count(& noOfFields);
while (true) //REPLACE THIS EXPRESSION BY EOF chk if EOF HAS BEEN rEACHED OR NOT.
{
// Traversing through the Fields collection to get the values.
for(nIndex = 0; nIndex < noOfFields; nIndex++)
{
if(csTemp[0] == '\0')
strcpy(csTemp, "The records are: \n");
// else
// strcpy(csTemp, "The Next Record is: \n");
strcat(csTemp, VyomaRecordset->Fields->GetItem(_variant_t((long)nIndex))->Name );
strcat(csTemp, " = ");
varValue = VyomaRecordset->Fields->GetItem(_variant_t((long)nIndex))->Value;
if(varValue.vt == VT_BSTR)
{
strcat(csTemp, _com_util::ConvertBSTRToString(varValue.bstrVal));
}
else
if(varValue.vt == VT_I4)
{
char temp[1024] = {0, };
sprintf(temp, "%d\n", varValue.iVal);
strcat(csTemp, temp);
}
} // End of For loop.
// MessageBox(NULL, csTemp, "Record", 0);
VyomaRecordset->MoveNext();
printf("%s\n",csTemp);
}
return 0;
}
This is my code i wanted to enter the data into my MS Access database... so plz tell me how to do tat i tried doin
CODE
VyomaDB.Open("", "", "Provider=MSDASQL.1;Persist Security Info=True;DSN=testMDB");
VyomaRecordset = VyomaDB.Execute("Insert into emp_table values(3,abc");
but it doesn't update... so please help in addin data into d db