|
|
使用自定义的类CSetODBC(二) |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
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 + '\t'); } strOutPut += "\n"; rs.MoveNext(); } rs.Close(); AfxMessageBox(strOutPut); }
db.Close();
}
3,相关信息记录在f:\\setodbc.con,其内容为: [test] DSN=testodbc_sql UID=sa PWD=
4,如果用户想重新设置ODBC,则: void CTestODBCDlg::OnResetOdbc() { CSetODBC dlg; dlg.SetFileName( "f:\\setodbc.con"); dlg.SetAppName("test"); const CString strConnect = dlg.GetConnectStr(true);//重新设置ODBC }

|
|
相关文章:相关软件: |
|