qq_27450937 2016-10-08 01:51 采纳率: 0%
浏览 1265

综合人事管理系统登录模块出现debug error

一个星期都没有解决,我都哭了,一个小项目就止步这了,请各位大神帮帮我吧.....
图片说明
怎么样都取消不了,帮帮忙啊
//我也只能附加个大概,我百度云有完整代码http://pan.baidu.com/s/1jIg6DJg
void CLoginDlg::OnOK() //这是登录模块
{
// TODO: Add extra validation here

CDialog::OnOK();

UpdateData(TRUE);//把对话框中的值传递到变量中
//检查数据有效性
if(m_username=="")
{
MessageBox("请输入用户名:");
return;
}
if(m_pwd=="")
{
MessageBox("请输入密码:");
return;
}
//定义CUsers对象,用于从数据库Users中读取数据
CUsers user;
user.getdata(m_username);//从数据库读取到c++的类中
//如果读取的数据与用户输入数据不同则返回
if(user.getpwd()!=m_pwd) //getpwd从类中返回列中的值
{
MessageBox("用户输入不正确!");
return;
}
CDialog::OnOK();
}

CUsers::CUsers()//这是把users表封装成类
{
username="";
pwd="";
user_type=0;
}
CString CUsers::getusername() //从类中返回username
{
return username;
}
CString CUsers::getpwd()
{
return pwd;
}
int CUsers::getuser_type()
{
return user_type;
}
void CUsers::set_username(CString cusername)
{
username=cusername;
}
void CUsers::set_pwd(int cpwd)
{
pwd=cpwd;
}
void CUsers::set_user_tupe(int cusertype)
{
user_type=cusertype;
}

void CUsers::getdata(CString cusername)  //从数据库读取到c++【不能用cusername,因为是从数据库读】
{
    ADOConn m_adoconn;
    m_adoconn.OnInitDBConnect();
_bstr_t vSQL;
vSQL="select *from users where username='cusername'";//字符串的sql语句
//执行select语句
_RecordsetPtr m_precordset;
m_precordset=m_adoconn.GetRecordSet(vSQL); //返回结果集到m_precordset
//返回各列的值
if(m_precordset->adoEOF==1)
    CUsers();
else
{                                                  //atoi()把int改为CString
    username=(LPCTSTR)(_bstr_t)m_precordset->GetCollect("username"); //getcollect()从结果集中读取相应列的值,返回值为_variant_t型
    pwd=(LPCTSTR)(_bstr_t)m_precordset->GetCollect("pwd");
    user_type=atoi((LPCTSTR)(_bstr_t)m_precordset->GetCollect("user_type"));
}
//断开与数据库的链接
m_adoconn.ExitConnect();

}


void CUsers::sql_insert()
{
ADOConn m_adoconn;
m_adoconn.OnInitDBConnect();
//设置insert语句
//CString strWage;
//strWage.Format("%f,Wage");  float转换为字符串形式
_bstr_t vSQL;
vSQL="insert into users values(username,pwd,user_tupe))";
//执行insert语句
m_adoconn.ExecuteSQL(vSQL);
//断开与数据库的链接
m_adoconn.ExitConnect();

}

void CUsers::sql_update_pwd(CString cusername)
{ 
ADOConn m_adoconn;
m_adoconn.OnInitDBConnect();
//设置insert语句
//CString strWage;
//strWage.Format("%f,Wage");  float转换为字符串形式
_bstr_t vSQL;
vSQL="updata users set pwd=pwd where username='cusername'";
//执行insert语句
m_adoconn.ExecuteSQL(vSQL);
//断开与数据库的链接
m_adoconn.ExitConnect();
}


void CUsers::sql_delete(CString cusername)
{
ADOConn m_adoconn;
m_adoconn.OnInitDBConnect();
//设置insert语句
//CString strWage;
//strWage.Format("%f,Wage");  float转换为字符串形式
_bstr_t vSQL;
vSQL="delete from users where username='cusername'";
//执行insert语句
m_adoconn.ExecuteSQL(vSQL);
//断开与数据库的链接
m_adoconn.ExitConnect();
}

BOOL CFwzlDlg::OnInitDialog() //这是在主对话框初始化时候调用登录模块
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
        pSysMenu->AppendMenu(MF_SEPARATOR);
        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
}

// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon

// TODO: Add extra initialization here
 _variant_t vIndex;

vIndex=long(0);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(0); //_variant_t类型在 COMDEF.H中
vIndex=long(1);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex=long(2);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(40);
vIndex=long(3);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(100);
vIndex=long(4);
m_datagrid.GetColumns().GetItem(vIndex).SetWidth(90);

CLoginDlg dlg;

extern CUsers curUser; //c++声明必须在前面
if(dlg.DoModal()!=IDOK) //domadal()函数返回对话框的传递的消息
OnOK();
else
//读取用户信息到 全局类curUser对象
curUser.getdata(dlg.m_username);
return TRUE; // return TRUE unless you set the focus to a control
}

void ADOConn::OnInitDBConnect() //以下是连接数据库的函数
{
//初始化ole/com库环境,为访问ado接口做准备
::CoInitialize(NULL); //I的大写,和l的小写尽然一样!!!!!!!!!!!!!!!!!!!!!!!!
try
{
//创建Connection对象
m_pConnection.CreateInstance("ADODB.Connection");
//设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect="Provider=SQLOLEDB;Server=LIQI;Database=fwzl;uid=sa;pwd=qi7250831;";
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
//捕捉异常
catch(_com_error e)
{
//显示错误信息
AfxMessageBox(e.Description());
}
}

RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
try
{
//连接数据库,如果connection对象为空,则重新连接数据库
if(m_pConnection==NULL)
OnInitDBConnect();
//创建记录集对象
m_pRecordset.CreateInstance(
_uuidof(Recordset)); //用来获取 某种结构、接口及其指针、引用、变量 所关联的GUID,类似于某些语言中获取类型 typeof 这样的操作。
//取得表中的记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);//源,activestring,游标类型,锁定类型,option(source参数的类型)
}
//捕捉异常
catch(_com_error e)
{
//显示出错信息
AfxMessageBox(e.Description());
}
//返回结果集
return m_pRecordset;
}
BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
{
try
{
//是否已经连接数据库
if(m_pConnection==NULL)
OnInitDBConnect();
m_pConnection->Execute(bstrSQL,NULL,adCmdText);
return true;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
}//程序调用Connetion对象的Execute方法执行SQL语句,不返回结果集,如果执行成功,则返回true
void ADOConn::ExitConnect()
{
//关闭记录集和连接
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
//释放环境
::CoUninitialize(); //关闭ole/com数据库,释放资源
}

  • 写回答

4条回答 默认 最新

  • 云想衣裳丶花想容 2016-10-08 01:53
    关注

    这描述的也太简单了。光凭这两张图我是看不出来哪里的问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题