Hallo,
ich muss für ein Intranet Programm auf eine fremde Datenbank zugreifen und Infos reinschreiben. Ich habe eine C++ Beispiellösung gefunden, aber habe keine Ahnung von C++. Ich habe gerade mit c# angefangen.
Kann jemand mir helfen folgendes Beispiel in C# umzusetzen. DANKE IM VORAUS!
Example 1: Creating a new user account
As an example, we will try to insert a new user ”mary” into OmniTracker’s database.
This imports the definitions from the OmniTracker Automation interface.
if (FAILED(hr))
{
AfxMessageBox ("Cannot initialize COM!");
return FALSE;
}
ich muss für ein Intranet Programm auf eine fremde Datenbank zugreifen und Infos reinschreiben. Ich habe eine C++ Beispiellösung gefunden, aber habe keine Ahnung von C++. Ich habe gerade mit c# angefangen.
Kann jemand mir helfen folgendes Beispiel in C# umzusetzen. DANKE IM VORAUS!
Example 1: Creating a new user account
As an example, we will try to insert a new user ”mary” into OmniTracker’s database.
- Create a new dialog-based project using the ”MFC AppWizard (exe)”.
Add a button called ”Add User” to the dialog. - Assign a handler OnAddUser() to the button, and fill it with the following code:
Code:
IOtApplicationPtr pApp;
HRESULT hr = pApp.CreateInstance(__uuidof(OtApplication), NULL,
CLSCTX_INPROC_SERVER);
if (FAILED(hr))
{
CString str;
str.Format ("CreateInstance() failed: 0x%08lx",
(ULONG) hr);
AfxMessageBox (str);
}
try {
IOtSessionPtr pSession;
pSession = pApp->MakeSession("hostname", 4567"superuser", "password");
IOtUsersPtr pUsers;
pUsers = pSession->Users;
IOtUserPtr pUser;
pUser = pUsers->Add();
pUser->LoginName = "mary";
pUser->EmailAddress = "mary@company.com";
pUser->Password = "65gh45";
pUser->DisplayName = "Mary";
pUser->Save();
} catch(_com_error& e) {
_bstr_t bstrDescription(e.Description());
AfxMessageBox((LPCTSTR) bstrDescription);
}
- At the top of the file containing OnAddUser(), add the following line:
This imports the definitions from the OmniTracker Automation interface.
- Make sure, that the OmniTracker installation directory is part of the list of the C++ preprocessor ‘s include directories.
- In the InitInstance() routine of your application, initialize COM by including the following lines:
if (FAILED(hr))
{
AfxMessageBox ("Cannot initialize COM!");
return FALSE;
}
- Compile and link the source files, and execute the program.