I use a DBmemo edit the database record but it always give the following error message when update the database.
"Command text was not set for the command object".
How can I make changes to the database record with the DB aware controls?
Thanks.
Shouxi Wang
Gas Liquids Engineering Ltd.
Update of the SQL database
-
Guest
Thanks.
I tried the example of SDAC and it works when I set the sql as "Select * from flareReport. If I set the sql as below there will be an error message "Update failed. Found 4 Records" when I made some modification in the linked DBMemo and the sqlFlareRpt update the record.
Thanks again.
AnsiString sql =
"SELECT CAST(Flare + 1 AS smallint) AS [No],\
CAST(TimeStart- 2 AS datetime) AS [Start Time], \
CAST(TimeEnd - 2 AS datetime) AS [End Time], \
DATEDIFF(n, TimeStart, TimeEnd) AS [Duration], \
CAST(FlowMax AS decimal(10, 3)) AS [MaxFlow], \
CAST(FlowMean AS decimal(10, 3)) AS [MeanFlow], \
CAST(FlowTotal AS decimal(10, 3)) AS [Total Volume], \
CAST(H2SMoleP AS decimal(10, 3)) AS [H2S Mole %], \
CAST(H2SMean AS decimal(10, 3)) AS [H2S Mean], \
CAST(H2STotal AS decimal(10, 3)) AS [H2S Flared], \
Reasons \
FROM FlareReport ";
if( flare > 0 || tstart > 0.0 || tend > 0.0 ) {
sql += "WHERE ";
bool hasCondition = false;
if( flare > 0 ) {
hasCondition = true;
sql += "(Flare =" + AnsiString(flare - 1) + AnsiString( ")" );
}
if( tstart > 0.0 ) {
if( hasCondition ) sql += " AND (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
else {
hasCondition = true;
sql += " (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
}
}
if( tend > 0.0 ) {
if( hasCondition ) sql += " AND (TimeEnd SQL->Count>0) sqlFlareRpt->SQL->Clear();
sqlFlareRpt->SQL->Add( sql );
sqlFlareRpt->Open();
sqlFlareRpt->Edit();
btnOK->Enabled = false;
BitBtn9->Enabled = sqlFlareRpt->RecordCount > 0;
I tried the example of SDAC and it works when I set the sql as "Select * from flareReport. If I set the sql as below there will be an error message "Update failed. Found 4 Records" when I made some modification in the linked DBMemo and the sqlFlareRpt update the record.
Thanks again.
AnsiString sql =
"SELECT CAST(Flare + 1 AS smallint) AS [No],\
CAST(TimeStart- 2 AS datetime) AS [Start Time], \
CAST(TimeEnd - 2 AS datetime) AS [End Time], \
DATEDIFF(n, TimeStart, TimeEnd) AS [Duration], \
CAST(FlowMax AS decimal(10, 3)) AS [MaxFlow], \
CAST(FlowMean AS decimal(10, 3)) AS [MeanFlow], \
CAST(FlowTotal AS decimal(10, 3)) AS [Total Volume], \
CAST(H2SMoleP AS decimal(10, 3)) AS [H2S Mole %], \
CAST(H2SMean AS decimal(10, 3)) AS [H2S Mean], \
CAST(H2STotal AS decimal(10, 3)) AS [H2S Flared], \
Reasons \
FROM FlareReport ";
if( flare > 0 || tstart > 0.0 || tend > 0.0 ) {
sql += "WHERE ";
bool hasCondition = false;
if( flare > 0 ) {
hasCondition = true;
sql += "(Flare =" + AnsiString(flare - 1) + AnsiString( ")" );
}
if( tstart > 0.0 ) {
if( hasCondition ) sql += " AND (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
else {
hasCondition = true;
sql += " (TimeStart >= " + AnsiString(tstart) + AnsiString( ")" );
}
}
if( tend > 0.0 ) {
if( hasCondition ) sql += " AND (TimeEnd SQL->Count>0) sqlFlareRpt->SQL->Clear();
sqlFlareRpt->SQL->Add( sql );
sqlFlareRpt->Open();
sqlFlareRpt->Edit();
btnOK->Enabled = false;
BitBtn9->Enabled = sqlFlareRpt->RecordCount > 0;