top
Loading...
利用ISAPI實現向數據庫中添加記錄(四)
4、ISAPI 應 用 程 序 的 編 寫

我 們 利 用 SQL 語 句 可 嵌 入 在 應 用 程 序 中 的 特 點, 把 SQL 的 有 關 請 求 語 句 嵌 入 在 ISAPI 交 互 程 序 中。 ISAPI 交 互 程 序 用 Visual C++ 編 寫, 以 下 是 實 現 向 中 藥 數 據 庫 的 表 CMT1 中 添 加 記 錄 的 主 要 程 序 段:


// 建 立 一 個 CZY 類 的 成 員 函 數 FileWrite1Entry, 實 現 向 中 藥 數 據 庫 的 表 CMT1 中 添 加 記 錄
void CZY::FileWrite1Entry(CHttpServerContext* pCtxt, LPTSTR pstrFileName)
{
const unsigned REC_NUM=1; // REC_NUM(數據文件中記錄個數)
const unsigned LINE=9; // LINE(表中數據域的個數)
const unsigned COLUMN=6000; // COLUMN(每個數據域中字符的最大個數)
char c,data[LINE][COLUMN];
FILE *fp;
StartContent(pCtxt); //HTML頭格式
WriteTitle(pCtxt); //HTML標題
Cstring stringSql;
Cstring strQuery;
Cstring strOutput;
Cstring pstrZY00,pstrZY01,pstrZY02,pstrZY03,pstrZY04,pstrZY05,
pstrZY06,pstrZY07,pstrZY08;
//以"讀"的方式打開文件名為pstrFileName的文件
if (!(fp = fopen (pstrFileName, "r")))
{
*pCtxt << "< center>< font color='red'>Warning: < /font>Cannot open this file.< /center>";
return;
}
//從文件中讀取數據
for(int k=0; k< REC_NUM; k++)
{
for(int I=0; I< LINE; I++)
{
//忽略"{"以前的說明性字符
do{
c=getc(fp);
}while(c!='{');
//讀取"{"和"}"之間的字符數據
for(int j=0; j< COLUMN; j++)
{
c=getc(fp);
if(c=='}')
{
data[I][j]='

北斗有巢氏 有巢氏北斗