Click here to Skip to main content
15,896,726 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDate and Time Pin
john563228-Oct-07 20:58
john563228-Oct-07 20:58 
AnswerRe: Date and Time Pin
Hamid_RT28-Oct-07 21:08
Hamid_RT28-Oct-07 21:08 
AnswerRe: Date and Time Pin
Nishad S28-Oct-07 21:08
Nishad S28-Oct-07 21:08 
AnswerRe: Date and Time Pin
chandu00428-Oct-07 21:37
chandu00428-Oct-07 21:37 
AnswerRe: Date and Time Pin
CodingLover28-Oct-07 21:43
CodingLover28-Oct-07 21:43 
AnswerRe: Date and Time Pin
Rahul Vaishnav28-Oct-07 21:52
Rahul Vaishnav28-Oct-07 21:52 
AnswerRe: Date and Time Pin
panthal29-Oct-07 1:34
panthal29-Oct-07 1:34 
QuestionInsert data to a SQL database on a click event. Pin
CodingLover28-Oct-07 20:51
CodingLover28-Oct-07 20:51 
Hi all,

I want to update a SQL database on a click event as follows.

<br />
void CSRFDBDlg::OnBnClickedAdd()<br />
{<br />
	UpdateData( TRUE ) ; // Allow upload the data<br />
<br />
	CString conStr ;	// Connection SQL query<br />
	HRESULT hr ;<br />
	_variant_t vtData ;<br />
	<br />
	conStr.Format ("SELECT * FROM RecordData") ;<br />
<br />
	ADODB::_ConnectionPtr pConn ;<br />
	ADODB::_RecordsetPtr pRecSet ; // Connection and record set<br />
<br />
	try<br />
	{<br />
		if(GetADOCon (srf_SQL, pConn, pRecSet))<br />
		{<br />
			hr = pRecSet->Open ( _bstr_t(conStr), pConn.GetInterfacePtr(), ADODB::adOpenDynamic, ADODB::adLockOptimistic, -1);<br />
<br />
			pRecSet->AddNew() ;<br />
<br />
	// Int value<br />
			int int_val = 345 ;<br />
			vtData.vt = VT_INT;<br />
			vtData.intVal = int_val ;<br />
			pRecSet->PutCollect(L"Destination List", vtData) ;<br />
<br />
			pRecSet->Update() ;<br />
			pRecSet->Close() ;<br />
<br />
			pConn->Close () ;<br />
		}<br />
	}<br />
<br />
	catch ( _com_error &e )<br />
	{<br />
		PassComError ( e ) ;<br />
	}<br />
}<br />


Here "Destination List" is one of the column of the table of database. Actually there are three more, but I set all of them allowed to NULL values. So need to worried about them, right? GetADOCon() also can be useful to you guys.

<br />
BOOL CSRFDBDlg::GetADOCon(CString ConStrTran, ADODB::_ConnectionPtr &pConn, ADODB::_RecordsetPtr &pRecSet)<br />
{<br />
	HRESULT hr;<br />
	BOOL bRet = FALSE;<br />
	CString csErrMess;<br />
<br />
	try <br />
	{<br />
		hr = pConn.CreateInstance(__uuidof(ADODB::Connection));	<br />
		if (FAILED(hr))<br />
		{<br />
			//Log("pConn.CreateInstance Failed \r\n");<br />
			return bRet;<br />
		}<br />
<br />
		hr = pRecSet.CreateInstance(__uuidof(ADODB::Recordset));<br />
		if (FAILED(hr))<br />
		{<br />
			//Log( "pRecSet.CreateInstance Failed \r\n");<br />
			return bRet;<br />
		}<br />
<br />
		hr = pConn->Open((_bstr_t)ConStrTran, L"", L"", -1L);<br />
		if (FAILED(hr))<br />
		{<br />
			csErrMess.Format ( "Open Database connection Failed ConnStr = %s\r\n" , ConStrTran  );<br />
			//Log ( csErrMess  );<br />
			return bRet;<br />
		}<br />
		else<br />
		{<br />
			bRet = TRUE;<br />
			csErrMess.Format ( "GetConnPtrs Successful for : %s" , ConStrTran  );<br />
			//Log ( csErrMess  );<br />
		}<br />
	}<br />
	catch ( _com_error &e )<br />
	{<br />
		PassComError ( e );<br />
		<br />
	}<br />
	return bRet;<br />
}<br />


I've try this now almost more than two days, the things is my code doesn't give any error, at compile time or at runtime. Can you guys tell me where I'm going wrong. Now I'm wried with this D'Oh! | :doh:



I appreciate your help all the time...
ErangaSmile | :)

NewsSoftware Engineers needed at Elektrobit (Beijing) Pin
zhaihuanyu28-Oct-07 20:34
zhaihuanyu28-Oct-07 20:34 
Questionhandling mouse event on a picture Pin
Joy_ee28-Oct-07 20:29
Joy_ee28-Oct-07 20:29 
QuestionRe: handling mouse event on a picture Pin
Nishad S28-Oct-07 20:36
Nishad S28-Oct-07 20:36 
AnswerRe: handling mouse event on a picture Pin
Hamid_RT28-Oct-07 20:43
Hamid_RT28-Oct-07 20:43 
QuestionDisable process termination Pin
hxhl9528-Oct-07 19:13
hxhl9528-Oct-07 19:13 
AnswerRe: Disable process termination Pin
Hamid_RT28-Oct-07 19:21
Hamid_RT28-Oct-07 19:21 
AnswerRe: Disable process termination Pin
Michael Dunn28-Oct-07 19:40
sitebuilderMichael Dunn28-Oct-07 19:40 
GeneralRe: Disable process termination Pin
Mark Salsbery29-Oct-07 5:38
Mark Salsbery29-Oct-07 5:38 
QuestionHow to insert data into ListBox(Something Different) Pin
ashishbhatt28-Oct-07 19:09
ashishbhatt28-Oct-07 19:09 
AnswerRe: How to insert data into ListBox(Something Different) Pin
Hamid_RT28-Oct-07 19:16
Hamid_RT28-Oct-07 19:16 
GeneralRe: How to insert data into ListBox(Something Different) Pin
ashishbhatt28-Oct-07 19:30
ashishbhatt28-Oct-07 19:30 
GeneralRe: How to insert data into ListBox(Something Different) Pin
ashishbhatt28-Oct-07 19:39
ashishbhatt28-Oct-07 19:39 
GeneralRe: How to insert data into ListBox(Something Different) Pin
ashishbhatt28-Oct-07 20:09
ashishbhatt28-Oct-07 20:09 
GeneralRe: How to insert data into ListBox(Something Different) Pin
Hamid_RT28-Oct-07 20:39
Hamid_RT28-Oct-07 20:39 
Questionprogress bar should run without any click event Pin
neha.agarwal2728-Oct-07 19:01
neha.agarwal2728-Oct-07 19:01 
AnswerRe: progress bar should run without any click event Pin
Nishad S28-Oct-07 20:32
Nishad S28-Oct-07 20:32 
QuestionNeed Help on memory allocation problem Pin
manish.patel28-Oct-07 18:56
manish.patel28-Oct-07 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.