用VC++6.0 开发ODBC程序连接数据库void COdbcdemoDlg::OnAddData() { UpdateData(true); // TODO: Add your control notification handler code here ClearEditValue(); //清空窗口 m_setdata.Open("ODBCtest",FALSE,FALSE,"ODBC;UID=us"); if(!m_setdata.IsOpen()) MessageBox("打开数据源失败"); /*********************************************************/ // 用类 CDatabbse 的函数ExecuteSQL来实现添加表中数据 CString str; str.Format("INSERT INTO ODBCdemo values('5','3','6','5','6','7','5','7','9','6','3','4','66','77')"); m_setdata.ExecuteSQL(str); /**************************************************************/ if(!m_setorder.CanUpdate()) { MessageBox("数据源不可以被更新"); return; } if(m_setorder.m_OID.IsEmpty()) { MessageBox("信息不能为空!"); return; }/*********************************************************************/ //用 类CRecordSet打开记录集 然后对 数据库进行添加 m_setorder 是CRecordSet的一个子类 //m_setorder.Open(); //求指导 为什么只有把这个注释掉程序才允许成功呢 // 说是游标混乱 怎么回事 if(!m_setorder.IsOpen()) MessageBox("error"); m_setorder.MoveNext(); m_setorder.AddNew(); m_setorder.m_CID="4"; m_setorder.m_EID="3"; m_setorder.m_OID="8"; m_setorder.m_freight="5"; m_setorder.m_RequireDate="44"; m_setorder.m_Orderdate="v"; m_setorder.m_shippeddate="cc"; m_setorder.m_shipvia="dd"; m_setorder.m_shipname="ee"; m_setorder.m_shipaddress="qq"; m_setorder.m_shipcity="gg"; m_setorder.m_shipregion="qq"; m_setorder.m_shipcountry="ds"; m_setorder.m_shippostalcode="ad"; m_setorder.Update(); m_setorder.Close();
}
|