Resetting the DataSource not working
Posted: Tue Oct 06, 2009 8:48 pm
I am try to change the SQL command at runtime and when I update the DataSource I get nothing. Below is my functions:
PS: If need be I can upload the sample project and a small data file.
//|----------------------------------------------------------------------------
void CTest_TChart_DB_Load_vADlg::OnBnClickedDisconnectbtn()
{
m_Chart.Series(0).SetDataSource((_variant_t)"");
m_Chart.Series(1).SetDataSource((_variant_t)"");
}
//|----------------------------------------------------------------------------
void CTest_TChart_DB_Load_vADlg::OnBnClickedDbgbutton()
{
CString aConnStr = "Provider=SQLOLEDB.1;"
"Integrated Security=SSPI;"
"Initial Catalog=Loaded_5k_4Quad_1Chart;"
"Data Source=(local);"
"Use Procedure for Prepare=1;"
"Auto Translate=True;"
"Packet Size=4096;"
"Workstation ID=BIGRED-64BIT;"
"Use Encryption for Data=False;"
"Tag with column collation when possible=False;";
CString UserStr = _T("");
CString PasswordStr = _T("");
CString SelectTargetSqlStr = _T("SELECT * FROM viewTargetCellData");
CString SelectWasteSqlStr = _T("SELECT * FROM viewWasteCellData" );
//| ADO
ADODB::_ConnectionPtr m_Connection;
ADODB::_RecordsetPtr m_TargetRecordSet;
ADODB::_RecordsetPtr m_WasteRecordSet;
HRESULT hr;
CString ErrStr;
try
{
hr = m_Connection.CreateInstance(__uuidof(ADODB::Connection));
if (FAILED(hr))
{
return;
}
hr = m_TargetRecordSet.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
hr = m_WasteRecordSet.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
}
catch(_com_error )
{
//BASIC_TRACEFUNCTION_MSG( static_cast<char *>(e.Description()) );
}
catch(...)
{
//BASIC_TRACEFUNCTION_MSG( "Unhandled Exception" );
}
hr = m_Connection->Open( aConnStr.AllocSysString(),
UserStr.AllocSysString(),
PasswordStr.AllocSysString(),
ADODB::adConnectUnspecified);
if (FAILED(hr))
return;
//| Open the Target RecordSet
hr = m_TargetRecordSet->Open( SelectTargetSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;
//| Open the Waste RecordSet
hr = m_WasteRecordSet->Open( SelectWasteSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;
m_Chart.Series(1).SetDataSource((_variant_t)m_TargetRecordSet);
m_Chart.Series(1).GetXValues().SetValueSource( "FwdSc_Peak" );
m_Chart.Series(1).GetYValues().SetValueSource( "Pmt_0_Peak" );
m_Chart.Series(0).SetDataSource((_variant_t)m_WasteRecordSet);
m_Chart.Series(0).GetXValues().SetValueSource( "FwdSc_Peak" );
m_Chart.Series(0).GetYValues().SetValueSource( "Pmt_0_Peak" );
m_Chart.Series(1).CheckDataSource();
m_Chart.Series(0).CheckDataSource();
//DisplaySourceStr();
return;
}
//|----------------------------------------------------------------------------
PS: If need be I can upload the sample project and a small data file.
//|----------------------------------------------------------------------------
void CTest_TChart_DB_Load_vADlg::OnBnClickedDisconnectbtn()
{
m_Chart.Series(0).SetDataSource((_variant_t)"");
m_Chart.Series(1).SetDataSource((_variant_t)"");
}
//|----------------------------------------------------------------------------
void CTest_TChart_DB_Load_vADlg::OnBnClickedDbgbutton()
{
CString aConnStr = "Provider=SQLOLEDB.1;"
"Integrated Security=SSPI;"
"Initial Catalog=Loaded_5k_4Quad_1Chart;"
"Data Source=(local);"
"Use Procedure for Prepare=1;"
"Auto Translate=True;"
"Packet Size=4096;"
"Workstation ID=BIGRED-64BIT;"
"Use Encryption for Data=False;"
"Tag with column collation when possible=False;";
CString UserStr = _T("");
CString PasswordStr = _T("");
CString SelectTargetSqlStr = _T("SELECT * FROM viewTargetCellData");
CString SelectWasteSqlStr = _T("SELECT * FROM viewWasteCellData" );
//| ADO
ADODB::_ConnectionPtr m_Connection;
ADODB::_RecordsetPtr m_TargetRecordSet;
ADODB::_RecordsetPtr m_WasteRecordSet;
HRESULT hr;
CString ErrStr;
try
{
hr = m_Connection.CreateInstance(__uuidof(ADODB::Connection));
if (FAILED(hr))
{
return;
}
hr = m_TargetRecordSet.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
hr = m_WasteRecordSet.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
}
catch(_com_error )
{
//BASIC_TRACEFUNCTION_MSG( static_cast<char *>(e.Description()) );
}
catch(...)
{
//BASIC_TRACEFUNCTION_MSG( "Unhandled Exception" );
}
hr = m_Connection->Open( aConnStr.AllocSysString(),
UserStr.AllocSysString(),
PasswordStr.AllocSysString(),
ADODB::adConnectUnspecified);
if (FAILED(hr))
return;
//| Open the Target RecordSet
hr = m_TargetRecordSet->Open( SelectTargetSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;
//| Open the Waste RecordSet
hr = m_WasteRecordSet->Open( SelectWasteSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;
m_Chart.Series(1).SetDataSource((_variant_t)m_TargetRecordSet);
m_Chart.Series(1).GetXValues().SetValueSource( "FwdSc_Peak" );
m_Chart.Series(1).GetYValues().SetValueSource( "Pmt_0_Peak" );
m_Chart.Series(0).SetDataSource((_variant_t)m_WasteRecordSet);
m_Chart.Series(0).GetXValues().SetValueSource( "FwdSc_Peak" );
m_Chart.Series(0).GetYValues().SetValueSource( "Pmt_0_Peak" );
m_Chart.Series(1).CheckDataSource();
m_Chart.Series(0).CheckDataSource();
//DisplaySourceStr();
return;
}
//|----------------------------------------------------------------------------