|
连接数据库小结
如果你的数据库是SQL server.你可以把下列代码复制到你的程序中,并按照注释内容做一些相应的改动。
public OS_STATUS,BILL_ID,recorder_number=0;
while(!recorder_number){
BILL_ID = create_input_dialog("Please give your bill ID");
# Here you can input your Bill_ID. If Bill_ID has been assigned a value,say,from the access,this step is not nessessary.
sql = "select OS_STATUS from tableName where BILL_ID="&BILL_ID;
db_connect("ConnectSample","driver=sql server;server=prcsgifs03;database=CNSMS;uid=sa;pwd=sa",30);
# In the case of choosing SQL server as the database, please refer driver as sql,server as your server name,so do you database,userId and password
db_execute_query("ConnectSample",sql,recorder_number);
#recorder_number is the number of records returnded from the database
if(recorder_number==1){
OS_STATUS = db_get_field_value("ConnectSample","#"&i,"OS_STATUS");
switch(OS_STATUS){
case "STATU1":
call statu1();
case "STATU2":
call statu2();
#...
default:
choice = create_list_dialog("Alert!","Do you want continue?","YES,NO");
if(choice=="YES"){
recorder_number = 0;
continue;
}
else
break;
}
}
else if(recorder_number==0)
continue;
else
report_msg("There are more then one OS_STATUS mapping to one Bill ID!");
}
db_disconnect("ConnectSample");
##################################################3
如果你的数据库是Access,只需设置好你的DSN,然后将
db_connect("ConnectSample","driver=sql server;server=prcsgifs03;database=CNSMS;uid=sa;pwd=sa",30);
这句改为
db_connet("ConnectSample","DNS=youdnsName",30);
然后,sql改为
sql = "select OS_STATUS from tableName where BILL_ID="&"'"&BILL_ID&"'";
#######################################################
由于你提供的信息不详细,我没有对代码进行验证。如有疑问可以提供代码或者跟贴。 |
|