Projekt Ordbog
Mig og en ven er ved at programmere en ordbog til et skoleprojekt, og vi er sådan set færdige .. Har har koden her:#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
using namespace std;
char word[1024];
char outconstr[1024]; // Returned connection string
int outconlen; // Length of returned connection string
char sqlstr[200]; // Insert
char *constr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=users.mdb;Uid=Admin;Pwd=";
char s[50];
char user[50];
char password[50];
int sl;
bool online = true;
SQLHENV Environment; //ODBC enviroment
SQLHDBC DataBaseConnect; //ODBC Connection
SQLHSTMT stmt; //ODBC Statement
SQLRETURN stat; //ODBC Return status
void startdatabase()
{
stat = SQLAllocEnv(&Environment);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in AllocEnv\n");
}
stat = SQLAllocConnect(Environment,&DataBaseConnect);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in AllocConnect\n");
}
stat = SQLDriverConnect(DataBaseConnect,NULL,
(SQLCHAR *)constr,(SQLSMALLINT)strlen(constr),
(SQLCHAR *)outconstr, (SQLSMALLINT)sizeof(outconstr),
(SQLSMALLINT *)&outconlen,SQL_DRIVER_COMPLETE);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in Connect\n");
}
stat = SQLAllocStmt(DataBaseConnect,&stmt);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in AllocStmt\n");
}
}
void readfromdb()
{
// READ DATA FROM DATABASE
sprintf(sqlstr,"SELECT password FROM info WHERE user = ('%s')",word);
stat = SQLExecDirect(stmt,(SQLCHAR *)sqlstr,strlen(sqlstr));
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in Read \n");
}
stat = SQLBindCol(stmt,1,SQL_C_CHAR,s,sizeof(s),(SQLINTEGER *)&sl);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error in BindCol\n");
}
for(;;)
{
stat = SQLFetch(stmt);
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO)) break;
s[sl] = '\0';
}
}
void deleteindb()
{
// DELETE IN DATABASE
sprintf(sqlstr,"DELETE from tabel WHERE id = 4");
stat = SQLExecDirect(stmt,(SQLCHAR *)sqlstr,strlen(sqlstr));
if((stat!=SQL_SUCCESS)&&(stat!=SQL_SUCCESS_WITH_INFO))
{
printf("Error, could not delete in database. \n");
}
}
void shutdowndb()
{
SQLFreeStmt(stmt,SQL_DROP);
SQLDisconnect(DataBaseConnect);
SQLFreeConnect(DataBaseConnect);
SQLFreeEnv(Environment);
}
int main()
{
while(online=true)
{
startdatabase();
cout << "Enter a word: \n";
cin >> word;
readfromdb();
cout << "Results: "<<s<<"\n";
shutdowndb();
}
system("pause");
return 0;
}
- Men vores problem er, at det kun er konsol baseret og vi har ikke nok tid til at sætte os ind i at lave et grafisk vindue .. Så vi ville høre, om der var nogle som kunne smide noget hurtigt sammen for os, så det ser lidt ud som denne: http://hotel.eucnord.net/dc69217/applikation.jpg
- Hvor den altså udskriver resultatet ..