I have an interface( MFC dialog based) which interacts with a MS access DB. DB has about 20 tables. almost all of them were created manually (i mean going to ms access and creating table using design view).
Now my program needed upgrade and so as to my DB. So to do it automatically I created a small code which will check if certain field is not there then add it.
I could update my table without error. but while updating any information to the table I get this error. I really dont know how to overcome this.
any kind of help will be great help....
Now my program needed upgrade and so as to my DB. So to do it automatically I created a small code which will check if certain field is not there then add it.
I could update my table without error. but while updating any information to the table I get this error. I really dont know how to overcome this.
any kind of help will be great help....
Code:
bool TableCreateQuote()
{
char executeStatement[1000];
DataBase.ExecuteSQL("CREATE TABLE Quotation1 (Quot_RevisionID TEXT(100) PRIMARY KEY,\
QuotationID TEXT(100),\
RevisionID TEXT(50),\
Lock INTEGER)");
return true;
}
bool TableUpdateQuotation()
{
while(ItTempVecRFQ_GUI != TempVecRFQ_GUI.end())
{
tempGUI1=*ItTempVecRFQ_GUI;
FieldName=tempGUI1.DBName;
FieldType=tempGUI1.DBVarType;
exStatement="ALTER TABLE \"Quotation_Information\" ADD ";
if(FieldType.Compare("INT")==0)//type-interger(INTEGER)
{
exStatement+=FieldName+" INTEGER";
}
else if(FieldType.Compare("DBL")==0)//type-double
{
exStatement+=FieldName+" DOUBLE";
}
else if(FieldType.Compare("STR")==0)//TXT-type(TEXT(100))
{
exStatement+=FieldName+" TEXT(100)";
}
else if(FieldType.Compare("NULL")==0)
{
ItTempVecRFQ_GUI++;
continue;
}
else
{
ItTempVecRFQ_GUI++;
continue;
}
strcpy(executeStatement,exStatement);
//chk whether colum present...
if(ChkColumnInTable("Quotation1",FieldName)==FALSE)
{
DataBase.ExecuteSQL(executeStatement);
}
exStatement="";
ItTempVecRFQ_GUI++;
}
return true;
}
//this function is called when user clicks update button in a dialog. This is
void OnButtonUpdate()
{
UpdateData(TRUE);
if( !m_RS_RFQ.Open("SELECT * FROM \"Quotation1\"") )
{
TRACE("Failed to run query: \"%s\"\n","SELECT * FROM \"Quotation1\"");
//return false;
}
else
{
//go to current record
//--
//
//starting updating fields in record
m_RS_RFQ.Edit();
while(--go over all field in gui)
m_RS1.Field(m_DBName)=strDate;
m_RS1.Field(m_DBName)=tempInt;
m_RS1.Field(m_DBName)=tempDbl;
m_RS1.Field(m_DBName)=tempStr;
//----end of while
m_RS_RFQ.Update();//I get error at this point...
//--
}
UpdateData(FALSE);
}
Comment