Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

hallo leute

folgendes problem:

ich soll eine verbindung mit dem SQL Server herstellen --> hat funktioniert!

ich soll aus unserer datenbank informationen auslesen und im fenster ausgeben

hat damit jemand erfahrung? welche befehle kann ich benutzen um mir das ausgeben zu lassen? ich hab die SDK schon links gemacht, aber bisher nichts brauchbares gefunden!

************************************************************************

#include "header.h"

//Connect to SQL Server

BOOL CALLBACK OpenSQL(HWND hwnd)

{

retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)

{

retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)

{

retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)

{

SQLSetConnectAttr(hdbc, 0/* (void*)SQL_LOGIN_TIMEOUT*/, 0, 0);

retcode = SQLConnect(hdbc, (SQLCHAR*) "*********", SQL_NTS,

(SQLCHAR*) "**", SQL_NTS,(SQLCHAR*) "*********", SQL_NTS);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)

{

retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)

{

SQLFreeHandle(SQL_HANDLE_STMT, hstmt);

MessageBox( hwnd, "Verbindung hergestellt!", 0, 0 );

return TRUE;

}

SQLDisconnect(hdbc);

}

else

{

MessageBox( hwnd, "Verbindung konnte nicht hergestellt werden", 0, 0 );

return FALSE;

}

SQLFreeHandle(SQL_HANDLE_DBC, hdbc);

}

}

SQLFreeHandle(SQL_HANDLE_ENV, henv);

return TRUE;

}}

//About Information

BOOL FAR PASCAL AboutProc (HWND hwnd,UINT message,UINT wParam,LONG lParam)

{

switch (message)

{

case WM_INITDIALOG:

return TRUE ;

case WM_COMMAND:

switch (wParam)

{

case IDOK:

EndDialog (hwnd,1);

return TRUE ;

}

}

return FALSE ;

}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,int nCmdShow)

{

static TCHAR szAppName[] = TEXT ("Klassenname");

HWND hwnd;

MSG msg;

WNDCLASSEX wndclassex = {0};

wndclassex.cbSize = sizeof(WNDCLASSEX);

wndclassex.style = CS_HREDRAW | CS_VREDRAW;

wndclassex.lpfnWndProc = WndProc;

wndclassex.cbClsExtra = 0;

wndclassex.cbWndExtra = 0;

wndclassex.hInstance = hInstance;

wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION);

wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW);

wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

wndclassex.lpszMenuName = "IDR_MENU";

wndclassex.lpszClassName = szAppName;

wndclassex.hIconSm = wndclassex.hIcon;

if (!RegisterClassEx (&wndclassex))

{

MessageBox (NULL, TEXT ("RegisterClassEx fehlgeschlagen!"),

szAppName, MB_ICONERROR);

return 0;

}

hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, // erweiterter Fensterstil

szAppName, // Name der Fensterklasse

TEXT ("******"), // Fenstertitel

WS_OVERLAPPEDWINDOW,

100, 100, 800, 600, NULL,

NULL, hInstance, NULL);

ShowWindow (hwnd, nCmdShow);

UpdateWindow (hwnd);

hInst = hInstance;

while (GetMessage (&msg, NULL, 0, 0))

{

TranslateMessage (&msg);

DispatchMessage (&msg);

}

return msg.wParam;

}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

switch (message)

{

case WM_COMMAND:

switch (wParam)

{

case 40001:

OpenSQL(hwnd); //Open Connection

return TRUE;

case 40002:

PostQuitMessage (0) ;

return 0 ;

case 40003:

DialogBox(0,"IDD_ABOUT",hwnd,MakeProcInstance(AboutProc,hInst));

return TRUE;

}

break ;

}

return DefWindowProc (hwnd, message, wParam, lParam);

}

Zum Auslesen:

Folgendes Beispiel liest zwei longs aus einer Tabelle:

const char* pszQuery = "SELECT * FROM Table";
SQLHSTMT hstatement;
if( RetCodeSuccess( SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstatement) ) ) {
long int long1 = 0, long2 = 0;
long len;
if( RetCodeSuccess( SQLExecDirect( hstatement, (SQLCHAR*) pszQuery, SQL_NTS ) ) ) {
SQLBindCol( hstatement, 1, SQL_C_SLONG, (SQLPOINTER) &long1, 4, &len );
SQLBindCol( hstatement, 2, SQL_C_SLONG, (SQLPOINTER) &long2, 4, &len );
SQLINTEGER nResultRows;
SQLRowCount( hstatement, &nResultRows );

if( nResultRows != 0 ) {
if( RetCodeSuccess( SQLFetch( hstatement ) ) ) {
// Auswerten...
}
}
}
SQLFreeHandle( SQL_HANDLE_STMT, hstatement );
}
[/CODE] Durch wiederholtes Aufrufen von SQLFetch kann man weitere Datensätze auslesen. RetCodeSuccess ist übrigens eine Hilfsfunktion, die ich mir selbst geschrieben habe:
[CODE]bool RetCodeSuccess( int nRetcode ) {
return nRetcode == SQL_SUCCESS || nRetcode == SQL_SUCCESS_WITH_INFO;
}

Macht den Code erheblich übersichtlicher. ;)

danke für deine antwort!

ich werde das morgen mal ausprobieren und bescheid geben ob es funktioniert hat!

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.