数据库修改记录

xlf000001 2011-05-14 09:43:49
if(!m_pSet.IsOpen())
{ //选择数据表并打开
m_pSet.Open(CRecordset::dynaset,_T("Select * from 表尾1"));//选择数据表并打开
}
//UpdateData();//把用户输入的内容赋予编辑框变量
m_pSet.MoveFirst();//第一个记录
m_pSet.Edit();
m_pSet.m_column1 =m_edit13;//把编辑框中的数据赋予数据库
m_pSet.m_column2 =m_edit14;
m_pSet.m_column3 =m_edit15;
m_pSet.m_column4 =m_edit16;
m_pSet.m_column5 =m_edit17;
m_pSet.m_column6 =m_edit18;
m_pSet.m_column7 =m_edit19;
m_pSet.m_column8 =m_edit20;
m_pSet.m_column9 =m_edit21;
m_pSet.Update();
m_pSet.Close();
UpdateData(FALSE);
出现了个很郁闷的问题,编辑框m_edit21中,如果什么也不加,会出现一个错误,字段m_column9说不能使0长度的字段
...全文
250 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
黑泡泡选手 2011-05-14
  • 打赏
  • 举报
回复
估计是代码位置有问题~~~
oyljerry 2011-05-14
  • 打赏
  • 举报
回复
在出错的位置打印一下错误信息等.
King_hhuang 2011-05-14
  • 打赏
  • 举报
回复
memset(&docInfo,0,sizeof(docInfo));
docInfo.cbSize=sizeof(DOCINFO);
docInfo.lpszDocName="Print Window";
if(printDC.StartDoc(&docInfo)<=0)
{
#ifdef _DEBUG
AfxMessageBox("Start Doc Failed");
#endif
printDC.Detach();
return;
}
printDC.StartPage();
printDC.SetMapMode(MM_TEXT);

GetClientRect(&rect);

printDC.StretchBlt(0,0,rect.Width()*5,rect.Height()*5,&m_memDC,0,0,rect.Width(),rect.Height(),SRCCOPY);

printDC.EndPage();
printDC.EndDoc();

printDC.Detach();

上面的代码应该都放在if(printDlg.DoModal()==IDOK)里面吧
必须是选择了打印,才执行上述代码啊
如果点了取消,这段代码不应该执行
黑泡泡选手 2011-05-14
  • 打赏
  • 举报
回复
错误信息是什么?
xlf000001 2011-05-14
  • 打赏
  • 举报
回复
大哥再帮我看看这段代码吧,有点问题,就是第一次打印可以,如果是第一次打印时按取消,接着在按打印就会出错,那个异常找不着
CDC *pDC;//屏幕DC
pDC = CDC::FromHandle(::GetDC(m_hWnd));//获取当前整个屏幕DC
int BitPERPixel = pDC->GetDeviceCaps(BITSPIXEL);//获得颜色模式
int Width = pDC->GetDeviceCaps(HORZRES);
int Height = pDC->GetDeviceCaps(VERTRES);


m_memDC.CreateCompatibleDC(pDC);

CBitmap memBitmap, *oldmemBitmap;//建立和屏幕兼容的bitmap
memBitmap.CreateCompatibleBitmap(pDC, Width, Height);

oldmemBitmap = m_memDC.SelectObject(&memBitmap);//将memBitmap选入内存DC
m_memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);//复制屏幕图像到内存DC



CDC printDC;
CRect rect;
CPrintDialog printDlg(FALSE);
DOCINFO docInfo;

if(printDlg.DoModal()==IDOK)
{
HDC hDC;
hDC=printDlg.GetPrinterDC();
if(!printDC.Attach(hDC))
return;
}
else
{
printDC.Detach();
return;
}

memset(&docInfo,0,sizeof(docInfo));
docInfo.cbSize=sizeof(DOCINFO);
docInfo.lpszDocName="Print Window";
if(printDC.StartDoc(&docInfo)<=0)
{
#ifdef _DEBUG
AfxMessageBox("Start Doc Failed");
#endif
printDC.Detach();
return;
}
printDC.StartPage();
printDC.SetMapMode(MM_TEXT);

GetClientRect(&rect);

printDC.StretchBlt(0,0,rect.Width()*5,rect.Height()*5,&m_memDC,0,0,rect.Width(),rect.Height(),SRCCOPY);

printDC.EndPage();
printDC.EndDoc();

printDC.Detach();
xlf000001 2011-05-14
  • 打赏
  • 举报
回复
呵呵 忘了改了
黑泡泡选手 2011-05-14
  • 打赏
  • 举报
回复
数据库中的字段设置为“可以空”了吗?
xlf000001 2011-05-14
  • 打赏
  • 举报
回复
不能是0长度的字符串

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧