使用自定义的类CSetODBC(二)

来源:互联网 发布:java编程基础学校 编辑:程序博客网 时间:2024/05/21 09:51
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
1,利用SQL词句理论上可以使用任何数据库,以sql为例.body.clientHeight)this.width=body.clientHeight" src="http://www.338888.com/VCShare/images/upfile/200461521239.jpg" onmousewheel="return yuzi_img(event,this)"> 2,使用方法void CTestODBCDlg::OnUseSql() {CSetODBC dlg;dlg.SetFileName( "f:/setodbc.con");dlg.SetAppName("test");const CString strConnect = dlg.GetConnectStr();//获得连接串CString strSQL;CDatabase db;db.OpenEx(strConnect);//打开数据库{//追加记录strSQL = "insert into character(Name,Country,Age) values('he','china',24)";db.ExecuteSQL(strSQL);}{//删除记录strSQL.Format("delete from character where Age = %d",24);db.ExecuteSQL(strSQL);}{//修改记录strSQL.Format("update character set age = 25 where name = 'he'");db.ExecuteSQL(strSQL);}//显示所有记录{CString strOutPut ;CRecordset rs(&db);rs.Open(CRecordset::snapshot,"select * from character");int nField = rs.GetODBCFieldCount();while(!rs.IsEOF()){for(int i = 0 ; i < nField ; i++){CString strTemp;rs.GetFieldValue((short)i,strTemp);strTemp.TrimLeft();strTemp.TrimRight();strOutPut +=(strTemp + '');}strOutPut += "";rs.MoveNext();}rs.Close();AfxMessageBox(strOutPut);}db.Close();}3,相关信息记录在f:/setodbc.con,其内容为:[test]DSN=testodbc_sql UID=saPWD=4,如果用户想重新设置ODBC,则:void CTestODBCDlg::OnResetOdbc() {CSetODBC dlg;dlg.SetFileName( "f:/setodbc.con");dlg.SetAppName("test");const CString strConnect = dlg.GetConnectStr(true);//重新设置ODBC}<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>