对ACCESS数据库增,删,查,改的源码(zz)

时间:2022-12-11 20:41:43

初学asp6.0,跪求对ACCESS数据库增,删, 查,改的源码悬赏分:20 - 解决时间:2007-1-18 13:29强人快来这星期要交差的啊- - 提问者: madfish110 - 一级最佳答案增加:insert into 表名 values('插入的内容')删除:delete from 表名 [where<条件>]查询:select* from 表名 where 条件修改:update 表名 set 列名=表达式 where 条件根据具体情况把相应的地方填上就行了。我说的很笼统,具体还要你自己体会。我建议你去买本数据库的书看看!很有用的! 0回答者: 9春天9 - 二级 2006-2-13 11:26我来评论>>提问者对于答案的评价:QQQ相关内容• 求vb6.0能对Access数据库文件中的数据进行增、删、改和查询操作 2010-1-8• 求一个asp.net(c#+access数据库)的企业网站管理系统源码 2 2009-6-23• VB中如何将access数据库显示到datagrid上 最好发个源码,谢谢 2007-9-27• flash+ASP或XML连接数据库access并验证用户和密码......(附源码) 1 2006-9-5• 求access数据库搜索源码,要能用,不用在修改的完整源码。 2009-1-5 更多关于增 删 查 改的问题>>查看同主题问题: access 数据库 源码等待您来回答 * 新婚蜜月旅游 * 刚新婚,准备一年后要宝宝,请问要提前做些什么准备工作?比如需要补充什么? * 求多乐的新婚生活这本书 * 新婚祝福短信 * 新婚梳妆镜放在什么地方?卧室比较小? * 肺结核初期患者会传染给新婚怀孕的妻子吗? * 新婚16夜硬盘版下载有的发网站无毒的? * 你们那的刘强结婚我首先祝他新婚快乐,可以告诉我他的手机号码吗。我是他朋友,我姓何,他认识我其他回答 共 3 条asp教程六七或八里有源码以及recordset使用http://bbs.eice.com.cn/index.asp?boardid=14 回答者: 重典 - 五级 2006-2-13 09:00建议你把动网论坛的源码下载下来看懂,你在ASP方面就很强了! 回答者: vbgame - 一级 2006-2-13 09:25// GridImageDlg.cpp : implementation file//#include "stdafx.h"#include "GridImage.h"#include "GridImageDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifextern CGridImageApp theApp;//james???/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public: CAboutDlg();// Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CGridImageDlg dialogCGridImageDlg::CGridImageDlg(CWnd* pParent /*=NULL*/) : CDialog(CGridImageDlg::IDD, pParent){ //{{AFX_DATA_INIT(CGridImageDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CGridImageDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CGridImageDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP DDX_GridControl(pDX, IDC_GRIDCTRL, m_GridCtrl); }BEGIN_MESSAGE_MAP(CGridImageDlg, CDialog) //{{AFX_MSG_MAP(CGridImageDlg) ON_NOTIFY(GVN_BEGINLABELEDIT, IDC_GRIDCTRL, OnGridSelChange ) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_ADD, OnAdd) ON_BN_CLICKED(IDC_INSERT, OnInsert) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_BN_CLICKED(IDC_SAVE, OnSave) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CGridImageDlg message handlersBOOL CGridImageDlg::OnInitDialog(){ CDialog::OnInitDialog(); try { pRecordset.CreateInstance("ADODB.Recordset"); pRecordset->Open("SELECT * FROM 基本信息图片",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); } catch(_com_error e)///捕捉异常 { AfxMessageBox("读取数据库失败!");///显示错误信息 } //获得主程序的路径并建立一个文件夹。 CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind ('//'); sPath=sPath.Left (nPos); CString strCrePath; //在程序路径下创建一个文件夹 strCrePath.Format("%s%s",sPath,_T("//临时图片//")); CreateDirectory(strCrePath,NULL); pBuffer = NULL; index = 1; m_GridCtrl.SetColumnCount(7); m_GridCtrl.SetFixedRowCount(1); m_GridCtrl.SetItemText(0, 0, _T("图片编号")); m_GridCtrl.SetItemText(0, 1, _T("桥梁编号")); m_GridCtrl.SetItemText(0, 2, _T("图片数据")); m_GridCtrl.SetItemText(0, 3, _T("图片类别名称")); m_GridCtrl.SetItemText(0, 4, _T("图片后缀")); m_GridCtrl.SetItemText(0, 5, _T("拍摄日期")); m_GridCtrl.SetItemText(0, 6, _T("图片描述")); int m_ncount ; m_ncount=pRecordset->GetRecordCount(); m_GridCtrl.SetRowCount(m_ncount+1); //设置图片数据栏灰色 while (m_ncount > 0) { m_GridCtrl.SetItemBkColour(m_ncount,2,RGB(236,233,216)); m_GridCtrl.SetItemText(m_ncount,2,_T("")); m_ncount--; } int row = 1; while (!pRecordset->adoEOF) { CString str; FieldsPtr pFields = pRecordset->Fields; FieldPtr pField = pFields->GetItem(0L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 0L,(char*)(_bstr_t)pField->Value); pField = pFields->GetItem(1L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 1L, (char*)(_bstr_t)pField->Value); pField = pFields->GetItem(2L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 3L,(char*)(_bstr_t)pField->Value); pField = pFields->GetItem(3L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 4L, (char*)(_bstr_t)pField->Value); pField = pFields->GetItem(5L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 5L, (char*)(_bstr_t)pField->Value); pField = pFields->GetItem(6L); if (pField->Value.vt != VT_NULL) m_GridCtrl.SetItemText(row, 6L, (char*)(_bstr_t)pField->Value); //读取图片数据 nSize = pRecordset->GetFields()->GetItem("图片数据")->ActualSize; if (nSize <= 0) { m_GridCtrl.SetItemText(row,2L,_T("")); } if(nSize > 0) { _variant_t varBLOB; varBLOB = pRecordset->GetFields()->GetItem("图片数据")->GetChunk(nSize); if(varBLOB.vt == (VT_ARRAY | VT_UI1)) { if(pBuffer = new BYTE [nSize+1]) ///重新申请必要的存储空间 { char *pBuf = NULL; SafeArrayAccessData(varBLOB.parray,(void **)&pBuf); memcpy(pBuffer,pBuf,nSize); ///复制数据到缓冲区 SafeArrayUnaccessData (varBLOB.parray); } } //保存到临时文件中 CString strExt; strExt.Format("%s%s",_T("."),m_GridCtrl.GetItemText(row,4)); CString str; str.Format("%s%d%s",strCrePath,index,strExt); //文件名和后缀名 CFile outFile(str,CFile::modeCreate|CFile::modeWrite); outFile.Write(pBuffer,nSize); CString strindex; strindex.Format("%d",index); m_GridCtrl.SetItemText(row,2,strindex); index++; } row++; pRecordset->MoveNext(); } return TRUE; // return TRUE unless you set the focus to a control}void CGridImageDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); }}// If you add a minimize button to your dialog, you will need the code below// to draw the icon. For MFC applications using the document/view model,// this is automatically done for you by the framework.void CGridImageDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); }}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CGridImageDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon;}void CGridImageDlg::OnAdd() { //添加一行 int rowcount = m_GridCtrl.GetRowCount(); m_GridCtrl.SetRowCount(rowcount+1); //设置该行属性,颜色,不可以修改,字段 m_GridCtrl.SetItemBkColour(rowcount,2,RGB(236,233,216)); CString strindex; strindex.Format("%d",index); m_GridCtrl.SetItemText(rowcount,2,strindex); index++; //添加日期数据 CTime nTime = CTime::GetCurrentTime(); CString str; str.Format("%d-%d-%d",nTime.GetYear(),nTime.GetMonth(),nTime.GetDay()); m_GridCtrl.SetItemText(rowcount, 5, str); //设置光标,自动滚动到最后一行 SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; si.nPos = 20000; m_GridCtrl.SetScrollInfo(SB_VERT,&si,TRUE); m_GridCtrl.SetFocusCell(rowcount,0);}void CGridImageDlg::OnInsert() { int row = m_GridCtrl.GetFocusCell().row; if (row==-1) { MessageBox(_T("请选择插入位置")); return; } int rowcount = m_GridCtrl.GetRowCount(); m_GridCtrl.InsertRow("",row); m_GridCtrl.SetFocusCell(row,0); m_GridCtrl.SetRowHeight(row,25); //设置该行属性,颜色,字段 m_GridCtrl.SetItemBkColour(row,2,RGB(236,233,216)); CString strindex; strindex.Format("%d",index); m_GridCtrl.SetItemText(row,2,strindex); index++; //添加日期数据 CTime nTime = CTime::GetCurrentTime(); CString str; str.Format("%d-%d-%d",nTime.GetYear(),nTime.GetMonth(),nTime.GetDay()); m_GridCtrl.SetItemText(row, 5, str); m_GridCtrl.Invalidate();}void CGridImageDlg::OnDelete() { int row = m_GridCtrl.GetFocusCell().row; if( row == -1) { MessageBox(_T("请选择要删除的行")); return; } if (row > 0) { m_GridCtrl.DeleteRow(row); } //设置光标位置 if (m_GridCtrl.GetRowCount() > row) m_GridCtrl.SetFocusCell(row,0); else m_GridCtrl.SetFocusCell(m_GridCtrl.GetRowCount()-1,0); m_GridCtrl.Invalidate();}void CGridImageDlg::OnSave() { try { pRecordset.CreateInstance("ADODB.Recordset"); pRecordset->Open("SELECT * FROM 基本信息图片",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); } catch(_com_error e)///捕捉异常 { AfxMessageBox("读取数据库失败!");///显示错误信息 } //删除所有记录 while (!pRecordset->adoEOF) { pRecordset->Delete(adAffectCurrent);///删除当前记录 pRecordset->MoveNext(); } int m_Rcount = 1; while (m_Rcount < m_GridCtrl.GetRowCount()) { pRecordset->AddNew(); if(m_GridCtrl.GetItemText(m_Rcount,0)!="") pRecordset->Fields->GetItem(_variant_t("图片编号"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,0)); if(m_GridCtrl.GetItemText(m_Rcount,1)!="") pRecordset->Fields->GetItem(_variant_t("桥梁编号"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,1)); //获得文件名 CString m_sname; m_sname.Format("%s",m_GridCtrl.GetItemText(m_Rcount,2)); //获取扩展名 CString m_sExt; m_sExt.Format("%s%s",_T("."),m_GridCtrl.GetItemText(m_Rcount,4)); //获得主程序的路径 CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind ('//'); sPath=sPath.Left (nPos); //获取图片数据 CFile f; CString FilePathName; FilePathName.Format("%s%s%s%s",sPath,_T("//临时图片//"),m_sname,m_sExt); //文件名和后缀名 CFileException e; if(f.Open(FilePathName, CFile::modeRead | CFile::typeBinary, &e)) //打开了一个文件 { int nSize = f.GetLength(); //先得到文件长度 BYTE * pBuffer = new BYTE [nSize]; //按文件的大小在堆上申请一块内存 if (f.Read(pBuffer, nSize) > 0 ) //把文件读到pBuffer(堆上申请一块内存) { // +---------------------------------------------- BYTE *pBuf = pBuffer; ///下面这一大段是把pBuffer里的数据放到库中 VARIANT varBLOB; SAFEARRAY *psa; SAFEARRAYBOUND rgsabound[1]; if(pBuf) { rgsabound[0].lLbound = 0; rgsabound[0].cElements = nSize; psa = SafeArrayCreate(VT_UI1, 1, rgsabound); for (long i = 0; i < (long)nSize; i++) SafeArrayPutElement (psa, &i, pBuf++); varBLOB.vt = VT_ARRAY | VT_UI1; varBLOB.parray = psa; pRecordset->GetFields()->GetItem("图片数据")->AppendChunk(varBLOB); } delete [] pBuffer; //删掉堆上申请的那一块内存 pBuf=0; //以防二次乱用 f.Close(); } } if(m_GridCtrl.GetItemText(m_Rcount,3)!="") pRecordset->Fields->GetItem(_variant_t("图片类别名称"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,3)); if(m_GridCtrl.GetItemText(m_Rcount,4)!="") pRecordset->Fields->GetItem(_variant_t("图片后缀"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,4)); if(m_GridCtrl.GetItemText(m_Rcount,5)!="") pRecordset->Fields->GetItem(_variant_t("拍摄日期"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,5)); if(m_GridCtrl.GetItemText(m_Rcount,6)!="") pRecordset->Fields->GetItem(_variant_t("图片描述"))->Value=_bstr_t(m_GridCtrl.GetItemText(m_Rcount,6)); m_Rcount++; pRecordset->Update(); } }void CGridImageDlg::OnCancel() { //删除过程:先删除文件夹的文件,再删除文件夹 CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind ('//'); sPath=sPath.Left (nPos); CString strDelPath; strDelPath.Format("%s%s",sPath,_T("//临时图片"));//获得临时图片的路径 CFileFind tempFind; CString temp; temp=strDelPath+"//*.*";//遍历临时图片文件夹下所有文件 BeginWaitCursor(); BOOL IsFinded=tempFind.FindFile(temp); while(IsFinded) { IsFinded=tempFind.FindNextFile(); if(!tempFind.IsDots()) { if(tempFind.IsDirectory()) { CString tempStr; tempStr=tempFind.GetFileName(); tempStr=strDelPath+"//"+tempStr; DeleteFile(tempStr); } else { CString tempStr; tempStr=strDelPath+"//"+tempFind.GetFileName(); DeleteFile(tempStr); } } } tempFind.Close(); if(!RemoveDirectory(strDelPath)) { MessageBox("删除目录失败!","警告信息",MB_OK); } //关闭窗口 CDialog::OnCancel();}void CGridImageDlg::OnGridSelChange(NMHDR * pNotifyStruct, LRESULT * result ){ NM_GRIDVIEW* pNmgv = (NM_GRIDVIEW*)pNotifyStruct; *result = 0; //获得第3列,某行(首行除外) if ((pNmgv->iColumn == 2)&&(pNmgv->iRow != 0)) { dlgData.m_nrow = pNmgv->iRow-1; dlgData.m_sname = m_GridCtrl.GetItemText(pNmgv->iRow,2);//获得索引名 dlgData.m_OutFileName = m_GridCtrl.GetItemText(pNmgv->iRow,3); //获得文件名 dlgData.m_sEXt = m_GridCtrl.GetItemText(pNmgv->iRow,4); //获得扩展名 if (dlgData.m_sname == "") //如果选中的行没有图片编号 { CString strIndex; strIndex.Format("%d",index); m_GridCtrl.SetItemText(dlgData.m_nrow+1,2,strIndex); dlgData.m_sname = strIndex; index++; } if (dlgData.DoModal()==IDOK) { //如果浏览文件,获得文件名及扩展名 if (dlgData.FileTitle!=""||dlgData.FileEXt!="") { m_GridCtrl.SetItemText(dlgData.m_nrow+1,3,dlgData.FileTitle); m_GridCtrl.SetItemText(dlgData.m_nrow+1,4,dlgData.FileEXt); dlgData.FileTitle = ""; dlgData.FileEXt = ""; } } }}