1. In the resource view, create a new Resource dialog and add a class to the dialog box to set the class name to Sqldlg.
2. Drag to add Edit control and button controls in the dialog box and modify their IDs.
3. Add the following code in the SQLDlg.cpp
void Sqldlg::onbnclickedok () {//TODO: Add control notification handler code here CString str_id,str_name,str_job,str_edu,str_native,str_gen,str
_email,sql;
GetDlgItemText (idc_edit_id,str_id);
GetDlgItemText (Idc_edit_name, str_name);
GetDlgItemText (Idc_edit_job, str_job);
GetDlgItemText (idc_edit_edu, str_edu);
GetDlgItemText (idc_edit_native, str_native);
GetDlgItemText (Idc_edit_gen, Str_gen);
GetDlgItemText (Idc_edit_email, Str_email);
if (flag = = 1) {mysql mysql;
Mysql_init (&mysql); if (!mysql_real_connect (&mysql, "localhost", "root", "admin", "Test", 3306, NULL, 0)) {MessageBox ("database connection Failed")
;
} mysql_res *result;
Char *ch_query;
mysql_query (&mysql, "SET NAMES ' GB2312 '");
result = Mysql_store_result (&mysql);
Mysql_free_result (result); Sql. Format (_t ("INSERT into peronal_info values ('%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s ')"), str_id, Str_job, Str_name, Str_gen
, Str_native, str_edu, Str_email); int len = WideCharToMultiByte (CP_ACP, 0, SQL, SQL.) GetLength (), NULL, 0, NULL, NULL);
Char *p = new Char[len + 1]; WideCharToMultiByte (CP_ACP, 0, SQL, SQL.)
GetLength (), p, Len, NULL, NULL);
P[len] = ' the ';
int r = mysql_real_query (&mysql, P, strlen (p));
} if (flag = = 2) {mysql mysql;
Mysql_init (&mysql); if (!mysql_real_connect (&mysql, "localhost", "root", "admin", "Test", 3306, NULL, 0)) {MessageBox ("database connection Failed")
;
} mysql_res *result;
Char *ch_query;
mysql_query (&mysql, "SET NAMES ' GB2312 '");
result = Mysql_store_result (&mysql);
Mysql_free_result (result); Sql.
Format (_t ("Delete from peronal_info where Id_user = '%s ' and Name = '%s ';"), str_id, str_name); int len = WideCharToMultiByte (CP_ACP, 0, SQL, SQL.)
GetLength (), NULL, 0, NULL, NULL);
Char *p = new Char[len + 1]; WideCharToMultiByte (CP_ACP, 0, SQL, SQL.)
GetLength (), p, Len, NULL, NULL);
P[len] = ' the ';
int r = mysql_real_query (&mysql, P, strlen (p));
} if (flag = = 3) {mysql mysql;
Mysql_init (&mysql); if (!mysql_reAl_connect (&mysql, "localhost", "root", "admin", "Test", 3306, NULL, 0)) {MessageBox (_t ("Database connection Failed"));
} mysql_res *result;
Char *ch_query;
mysql_query (&mysql, "SET NAMES ' GB2312 '");
result = Mysql_store_result (&mysql);
Mysql_free_result (result); Sql. Format (_t ("update peronal_info set Job = '%s ', Name = '%s ', Gender = '%s ', Native = '%s ', education = '%s '), Email = '%s ' where
Id_user = '%s '), Str_job, Str_name, Str_gen, Str_native, str_edu, str_email,str_id); int len = WideCharToMultiByte (CP_ACP, 0, SQL, SQL.)
GetLength (), NULL, 0, NULL, NULL);
Char *p = new Char[len + 1]; WideCharToMultiByte (CP_ACP, 0, SQL, SQL.)
GetLength (), p, Len, NULL, NULL);
P[len] = ' the ';
int r = mysql_real_query (&mysql, P, strlen (p));
} Cdialog::onok (); }
4. Include the header file SQLDlg.h in the WeiboView.cpp and add the following code.
#include "SQLDlg.h"
void Cweiboview::onbtnadd ()
{
Sqldlg sql;
Sql.flag = 1;
Sql. DoModal ();
TODO: Add Command handler code here
}
void Cweiboview::onbtnsearch ()
{
Sqldlg sql;
Sql.flag = 0;
Sql. DoModal ();
TODO: Add Command handler code here
}
void Cweiboview::onbtndel ()
{
Sqldlg sql;
Sql.flag = 2;
Sql. DoModal ();
TODO: Add Command handler code here
}
void Cweiboview::onbtnchange ()
{
Sqldlg sql;
Sql.flag = 3;
Sql. DoModal ();
TODO: Add Command handler code here
}