Example #1
0
void LimitMappingScripwise::OnBnClickedBtnOk()
{
		_bstr_t valField1("");
		_bstr_t valField2("");		
		_bstr_t valField3("");
		_bstr_t cmd("");
		CString  strsqlcommand;				 	
		HRESULT hr = S_OK;		 
		CoInitialize(NULL);
          // Define string variables.		 
		_bstr_t strCnn("Provider=SQLOLEDB;SERVER=68.168.101.187;Database=tradedatabase;uid=sa;pwd=ok@12345;");		 
        _RecordsetPtr pRstAuthors = NULL;
 
      // Call Create instance to instantiate the Record set
      hr = pRstAuthors.CreateInstance(__uuidof(Recordset)); 
      if(FAILED(hr))
      {           
      }		
	 
	int noofrows=e_grid.GetNumberRows();
	for (int f_count=0;f_count<noofrows-1;f_count++)
	{
		CString strf=L"";
		valField1=e_grid.QuickGetText(0,f_count);
		strf=e_grid.QuickGetText(0,f_count);
		valField2=e_grid.QuickGetText(1,f_count);
		if (e_grid.QuickGetText(2,f_count)!=NULL )
		{
			valField3=e_grid.QuickGetText(2,f_count);
		}
		else
		{
			valField3="0";
		}
		if (strf!=L"")
		{
			cmd=cmd+"  delete  from Limit_Mapping where [login]='" + GridTradeAndOrder::m_selected_login + "' and symbol='" + valField1 + "'   insert into Limit_Mapping([login],symbol,limit,LimitSell) values('" + GridTradeAndOrder::m_selected_login + "','" + valField1 + "','" + valField2 + "','" + valField3 + "')";
		}
	}	
	
	pRstAuthors->Open(cmd,strCnn, adOpenStatic,adLockReadOnly,adCmdText);    			

	AfxMessageBox(L"Limit has been updated");
}
Example #2
0
void AddNewX() {
    // Define ADO object pointers. Initialize pointers on define.  
    _RecordsetPtr pRstEmployees = NULL;
    _ConnectionPtr pConnection = NULL;

    // Define Other variables  
    IADORecordBinding *picRs = NULL;   // Interface Pointer declared.(VC++ Extensions)     
    CEmployeeRs emprs;   // C++ class object     

    HRESULT hr = S_OK;

    // Replace Data Source value with your server name.  
    _bstr_t strCnn("Provider='sqloledb'; Data Source='My_Data_Source'; Initial Catalog='pubs'; Integrated Security='SSPI';");
    _bstr_t strId;
    _bstr_t strMessage;

    try {
        // Open a connection  
        TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
        pConnection->Open(strCnn, "", "", adConnectUnspecified);

        // Open employee table   
        TESTHR(pRstEmployees.CreateInstance(__uuidof(Recordset)));

        // You have to explicitly pass the Cursor type and LockType to the Recordset here  
        pRstEmployees->Open("employee", _variant_t((IDispatch *)pConnection, true),
            adOpenKeyset, adLockOptimistic, adCmdTable);

        // Open IADORecordBinding interface pointer for Binding Recordset to a class      
        TESTHR(pRstEmployees->QueryInterface(__uuidof(IADORecordBinding), (LPVOID*)&picRs));

        // Bind the Recordset to a C++ Class here     
        TESTHR(picRs->BindToRecordset(&emprs));

        // Get data from the user.The employee id must be formatted as first,middle and last   
        // initial, five numbers,then M or F to signify the gender. For example, the   
        // employee id for Bill A. Sorensen would be "BAS55555M".   
        printf("Enter Employee Id: ");
        myscanf(emprs.m_sz_empid, sizeof(emprs.m_sz_empid));
        strId = emprs.m_sz_empid;
        printf("Enter First Name: ");
        myscanf(emprs.m_sz_fname, sizeof(emprs.m_sz_fname));
        printf("Enter Last Name:");
        myscanf(emprs.m_sz_lname, sizeof(emprs.m_sz_lname));

        // Proceed if user entered id, the first and the last name.   

        if (strcmp(emprs.m_sz_empid, "") && strcmp(emprs.m_sz_fname, "") && strcmp(emprs.m_sz_lname, "")) {
            // This adds a new record to the table     
            // if (FAILED(hr = picRs->AddNew(&emprs)))  
            //_com_issue_error(hr);  
            TESTHR(picRs->AddNew(&emprs));

            // Show the newly added data  
            printf("New Record: %s  %s  %s \n", \
                emprs.lemp_empidStatus == adFldOK ? emprs.m_sz_empid : "<NULL>", \
                emprs.lemp_fnameStatus == adFldOK ? emprs.m_sz_fname : "<NULL>", \
                emprs.lemp_lnameStatus == adFldOK ? emprs.m_sz_lname : "<NULL>");
        }
        else
            printf("Please enter an employee id, first name and last name.\n");

        // Delete the new record because this is a demonstration.   
        pConnection->Execute("DELETE FROM EMPLOYEE WHERE emp_id = '" + strId + "'", NULL, adCmdText);
    }
    catch (_com_error &e) {
        // Notify the user of errors if any.  
        _variant_t vtConnect = pRstEmployees->GetActiveConnection();

        // GetActiveConnection returns connect string if connection  
        // is not open, else returns Connection object.  
        switch (vtConnect.vt) {
        case VT_BSTR:
            printf("Error:\n");
            printf("Code = %08lx\n", e.Error());
            printf("Message = %s\n", e.ErrorMessage());
            printf("Source = %s\n", (LPCSTR)e.Source());
            printf("Description = %s\n", (LPCSTR)e.Description());
            break;
        case VT_DISPATCH:
            PrintProviderError(vtConnect);
            break;
        default:
            printf("Errors occured.");
            break;
        }
    }

    // Clean up objects before exit.  Release the IADORecordset Interface here     
    if (picRs)
        picRs->Release();

    if (pRstEmployees)
        if (pRstEmployees->State == adStateOpen)
            pRstEmployees->Close();
    if (pConnection)
        if (pConnection->State == adStateOpen)
            pConnection->Close();
}