Resetting the DataSource not working

TeeChart for ActiveX, COM and ASP
Post Reply
jfrancis
Newbie
Newbie
Posts: 9
Joined: Fri Nov 02, 2007 12:00 am

Resetting the DataSource not working

Post by jfrancis » 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;
}
//|----------------------------------------------------------------------------

Yeray
Site Admin
Site Admin
Posts: 9617
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Resetting the DataSource not working

Post by Yeray » Wed Oct 07, 2009 8:58 am

Hi John Francis,

Yes, it would be helpful if you could send us a simple but complete example we can run as-is here.

Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jfrancis
Newbie
Newbie
Posts: 9
Joined: Fri Nov 02, 2007 12:00 am

Re: Resetting the DataSource not working

Post by jfrancis » Thu Oct 08, 2009 4:13 pm

I got it fixed here are the functions:

Also, I try to attach files but extension h is not allowed ... what is allowed and how would you like me to transfer the project to you?

//|----------------------------------------------------------------------------
void CTest_TChart_DB_Load_vADlg::DisplaySourceStr(void)
{
VARIANT vrDataSrc = m_Chart.Series(0).GetDataSource();
ADODB::_RecordsetPtr aRecordSet = (_variant_t)vrDataSrc;
_variant_t var;
var = aRecordSet->GetSource();
CString strSource = (_bstr_t(var.bstrVal));
// Source String
CString sourcestr;
sourcestr.Format("Source: %s", strSource );
m_Source.SetWindowText( sourcestr );

_variant_t varConnect;
varConnect = aRecordSet->GetActiveConnection();
ADODB::_ConnectionPtr aConnection = (_variant_t)varConnect;

CString strConn = aConnection->GetConnectionString();

CString connstr;
connstr.Format("Connection String:\n %s", strConn);
int count = connstr.Replace( _T(";"), _T(";\r\n") );



m_ConnEditCtrl.SetWindowText( connstr );
}
//|----------------------------------------------------------------------------
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=LoadTesting_5K_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::adOpenKeyset,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;

//| Open the Waste RecordSet
hr = m_WasteRecordSet->Open( SelectWasteSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenKeyset,
ADODB::adLockReadOnly,
ADODB::adCmdText );

if (FAILED(hr))
return;


m_Chart.Series(1).SetDataSource((_variant_t)m_TargetRecordSet.GetInterfacePtr());
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.GetInterfacePtr());
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;
}
//|----------------------------------------------------------------------------


void CTest_TChart_DB_Load_vADlg::OnBnClickedDbgbutton2()
{
CString aConnStr = "Provider=SQLOLEDB.1;"
"Integrated Security=SSPI;"
"Initial Catalog=LoadTesting_400K_4Chart;"
"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::adOpenKeyset,
ADODB::adLockReadOnly,
ADODB::adCmdText );
if (FAILED(hr))
return;

//| Open the Waste RecordSet
hr = m_WasteRecordSet->Open( SelectWasteSqlStr.AllocSysString(),
m_Connection.GetInterfacePtr(),
ADODB::adOpenKeyset,
ADODB::adLockReadOnly,
ADODB::adCmdText );

if (FAILED(hr))
return;


m_Chart.Series(1).SetDataSource((_variant_t)m_TargetRecordSet.GetInterfacePtr());
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.GetInterfacePtr());
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;
}

Yeray
Site Admin
Site Admin
Posts: 9617
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Resetting the DataSource not working

Post by Yeray » Tue Oct 13, 2009 11:34 am

Hi John Francis,
jfrancis wrote:Also, I try to attach files but extension h is not allowed ... what is allowed and how would you like me to transfer the project to you?
Have you tried attaching the files into a zip file? Also you can provably change the extension to attach the files and tell us the changes made.
Finally, if you find problems on the size limit for the attachment in this forums, you can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply