void CDlgpassword::OnLogin()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CSetdata *pset=new CSetdata();
CString strSQL;
strSQL.Format("select *from Admin");
pset->Open(); //打开数据库
if(strcmp(pset->m_Admin,m_username )) //比较输入账号
{ if(strcmp(pset->m_Password,m_password)){ //比较密码
CMyDlg dlg;
dlg.DoModal(); //跳转主页面
exit(0);
}
else
AfxMessageBox("用户名或密码错误!");
exit(0);
}
else
{
AfxMessageBox("用户名或密码错误!");
exit(0);
}这是代码,本人新手,高手勿喷
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CSetdata *pset=new CSetdata();
CString strSQL;
strSQL.Format("select *from Admin");
pset->Open(); //打开数据库
if(strcmp(pset->m_Admin,m_username )) //比较输入账号
{ if(strcmp(pset->m_Password,m_password)){ //比较密码
CMyDlg dlg;
dlg.DoModal(); //跳转主页面
exit(0);
}
else
AfxMessageBox("用户名或密码错误!");
exit(0);
}
else
{
AfxMessageBox("用户名或密码错误!");
exit(0);
}这是代码,本人新手,高手勿喷
解决方案 »
- GSM协议栈QQ 群:19280693
- 请做过大项目的同志给点经验。
- 高分求解!怎么建立客户/服务器方式的连接,急,急,急,等着回家过年!
- VC中如何复制、删除、移动文件
- [请教]如何与当前ie窗口联系
- 请问哪里有《VISUAL C++MFC扩展编程实例》的配套光盘下载?
- 调用CLISTBOX的ADDSTRING函数时出现的问题
- 请大家介绍一本关于VC的数据库编程的书!谢谢!
- 新手求一个基于MFC TCP/IP的简单网络界面程序 要源代码
- SetLayeredWindowAttributes(),link时说unresolved external symbol
- MFC中给按钮添加消息响应函数,添加不上?
- 怎样能统计到我写的软件有多少人再用?
然后查询记录集
在从查询到的记录集中找到你关注的字段名的值
最后做比较
strcmp等于0的时候才说明两个字符串相等
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
#if !defined(AFX_SETDATA_H__9B618C2A_9A50_48EF_938F_D02F037F7526__INCLUDED_)
#define AFX_SETDATA_H__9B618C2A_9A50_48EF_938F_D02F037F7526__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Setdata.h : header file
///////////////////////////////////////////////////////////////////////////////
// CSetdata recordsetclass CSetdata : public CRecordset
{
public:
CSetdata(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CSetdata)// Field/Param Data
//{{AFX_FIELD(CSetdata, CRecordset)
CString m_username;
CString m_number;
long m_1_____;
long m_2_____;
long m_3_____;
long m_4_____;
long m_5_____;
long m_userID;
CString m_Admin;
CString m_Password;
CString m_column3;
CString m_password;
CString m_address;
CString m_tel;
long m_allyongdian;
long m_shengyu;
long m_qianfeie;
//}}AFX_FIELD
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSetdata)
public:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
//}}AFX_VIRTUAL// Implementation
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SETDATA_H__9B618C2A_9A50_48EF_938F_D02F037F7526__INCLUDED_)CSetdata是连接数据库的
// Setdata.cpp : implementation file
//#include "stdafx.h"
#include "用电管理系统改.h"
#include "Setdata.h"
#include "afxdb.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CSetdataIMPLEMENT_DYNAMIC(CSetdata, CRecordset)CSetdata::CSetdata(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CSetdata)
m_username = _T("");
m_number = _T("");
m_1_____ = 0;
m_2_____ = 0;
m_3_____ = 0;
m_4_____ = 0;
m_5_____ = 0;
m_userID = 0;
m_column3 = _T("");
m_password = _T("");
m_Admin=_T("");
m_Password=_T("");
m_address = _T("");
m_tel = _T("");
m_allyongdian = 0;
m_shengyu = 0;
m_qianfeie = 0;
m_nFields = 17;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}
CString CSetdata::GetDefaultConnect()
{
return _T("ODBC;DSN=my data");
}CString CSetdata::GetDefaultSQL()
{
return _T("[Admin],[每月用电量信息],[用户登录信息],[用户信息卡]");
}void CSetdata::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CSetdata)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Long(pFX, _T("[1月分用电量]"), m_1_____);
RFX_Long(pFX, _T("[2月份用电量]"), m_2_____);
RFX_Long(pFX, _T("[3月份用电量]"), m_3_____);
RFX_Long(pFX, _T("[4月份用电量]"), m_4_____);
RFX_Long(pFX, _T("[5月份用电量]"), m_5_____);
RFX_Long(pFX, _T("[userID]"), m_userID);
RFX_Text(pFX, _T("[username]"), m_username);
RFX_Text(pFX, _T("[权限]"), m_column3);
RFX_Text(pFX, _T("[password]"), m_password);
RFX_Text(pFX, _T("[Password]"), m_Password);
RFX_Text(pFX, _T("[Admin]"), m_Admin);
RFX_Text(pFX, _T("[number]"), m_number);
RFX_Text(pFX, _T("[address]"), m_address);
RFX_Text(pFX, _T("[tel]"), m_tel);
RFX_Long(pFX, _T("[总用电量]"), m_allyongdian);
RFX_Long(pFX, _T("[电量余额(kwh)]"), m_shengyu);
RFX_Long(pFX, _T("[所欠费用(元)]"), m_qianfeie);
//}}AFX_FIELD_MAP
}/////////////////////////////////////////////////////////////////////////////
// CSetdata diagnostics#ifdef _DEBUG
void CSetdata::AssertValid() const
{
CRecordset::AssertValid();
}void CSetdata::Dump(CDumpContext& dc) const
{
CRecordset::Dump(dc);
}
#endif //_DEBUG
这是CSetdata下Assertvalid的代码
有userID、username、权限、password、Password、Admin
怎么有那么多用户名、密码、权限之类的呢而且你的用到的用户名又是Admin,到底都是写什么,晕死
CString strSQL;
strSQL.Format("select * from Admin where Admin='%s' and Password='%s'",m_username,m_password);
pset->m_pDatabase-> ExecSql(strSQL);
if(pset->GetRecordCount()>0)
AfxMessageBox("成功");
else
AfxMessageBox("失败");
file:dbcor .cpp
void AFXAPI AfxAssertValidObject(const CObject* pOb,
LPCSTR lpszFileName, int nLine)
{
if (pOb == NULL)
{
TRACE(traceAppMsg, 0, "ASSERT_VALID fails with NULL pointer.\n");
if (AfxAssertFailedLine(lpszFileName, nLine))
AfxDebugBreak();
return; // quick escape调试后在这里中断了
http://www.cnblogs.com/myzhijie/articles/1658559.html