/*sql.format(_t("delete from sellinfo where merchandise ='%s'"), m_name);
m_pconnection->execute((_bstr_t)sql, null, adcmdtext);
m_list.deleteitem(pos);*/
//ñéö¤sql×¢èëîêìâ
//_connectionptr
//sql = _t( "select * from sellinfo where merchandise = '1' or '1'='1' ");
// cstring m_name = "1' or '1'='1";
// sql.format("delete from sellinfo where merchandise = '%s'", m_name);
// m_pconnection->execute((_bstr_t)sql, null, adcmdtext);
//pcommand->commandtext="delete from sellinfo where merchandise = '%s'";
_commandptr pcommand(__uuidof(command));
m_precordset.createinstance(__uuidof(recordset));
pcommand->commandtext="delete from sellinfo where merchandise = ? ";
//pcommand->commandtext="delete from sellinfo where ? ";
pcommand->parameters->refresh();
//_parameterptr param=pcommand->createparameter(_bstr_t("121"), adbstr,adparaminput,strlen("121"), "121");
_parameterptr param=pcommand->createparameter(_bstr_t(" '1' or '1'='1' "), adbstr,adparaminput,strlen(" '1' or '1'='1' ")," '1' or '1'='1' ");
//pcommand->commandtext=" delete from sellinfo where merchandise = '1' or '1'='1' "; ->²»äüóãsqlæ´½ó
pcommand->activeconnection=m_pconnection;
pcommand->commandtype=adcmdtext;
//
messagebox("exe before");
m_precordset=pcommand->execute(null,null,adcmdtext); //??sql??
messagebox("over");
不要直接用使用者輸入的資料 如果資料庫包含惡意字元 這樣會導致 hack 填空 導致 delete from sellinfo where merchandise = '1' or '1'='1' 執行 資料全部刪除
cstring m_name = " '1' or '1'='1' ";
sql.format("delete from sellinfo where merchandise = %s ", m_name);
m_pconnection->execute((_bstr_t)sql, null, adcmdtext);
tryprst->close(); //關閉物件 pconn->close();
pcmd.release(); //釋放物件 prst.release(); pconn.release();
couninitialize(); //解除安裝com元件
3、實現插入記錄 coinitialize(null);
_connectionptr pconn(__uuidof(connection)); _recordsetptr prst(__uuidof(recordset)); _commandptr pcmd(__uuidof(command));
_variant_t recordsaffected; //申請乙個_variant_t型別的的變數
pconn->connectionstring="provider=microsoft.jet.oledb.4.0;data source=student.mdb";
pconn->open("","","",adconnectunspecified);
prst=pconn->execute("insert into stu (學號,姓名,電
話) values ('2222','dddd','123456')",&recordsaffected,adcmdtext);
//prst->close(); //若有此句可以實現插入,但會產生runtime錯誤提示 pconn->close(); pcmd.release(); prst.release(); pconn.release(); couninitialize();
4、實現刪除記錄
coinitialize(null);
_connectionptr pconn(__uuidof(connection)); _recordsetptr prst(__uuidof(recordset)); _commandptr pcmd(__uuidof(command));
_variant_t recordsaffected; //申請乙個_variant_t型別的的變數
pconn->connectionstring="provider=microsoft.jet.oledb.4.0;data source=student.mdb";
pconn->open("","","",adconnectunspecified);
prst=pconn->execute("delete from stu where 學號='2'",&recordsaffected,adcmdtext);
pconn->close(); pcmd.release(); prst.release(); pconn.release(); couninitialize();
登入方法及防止sql注入
登入查詢語句最好不要用連線字串查詢,防止sql注入。1 or 1 1 string username admin string password 123 string str 連線字串 using sqlconnection cnn newsqlconnection str else 登入查詢語句最...
ADO SQL問題及解決方法
1 ado連線sql,開啟資料集時,如果是單條語句的,後跟注釋,則執行時無結果集返回,如果是有分行符則正常 在查詢分析器當然是正常的 原因不詳,如 select from abc memo 無返回 select from abc slinkbreak memo 正常 2 刪除記錄時,出現bof 或 ...
PHP如何防止注入及開發安全
幻燈片 2 1 php 注入的基本原理 幻燈片 2 程式設計師的水平及經驗也參差不齊,相當大一部分程式設計師在編寫 的時候,沒有對 使用者輸入資料的合法性進行判斷,使應用程式存在安全隱患。使用者可以提交一段資料 幻燈片 2 sql 注入過程 庫查詢 根據程式返回的結果,獲得某些他想得知的資料,這就是...