当前位置: 代码迷 >> PB >> dropdownlistbox连接数据库,该怎么解决
  详细解决方案

dropdownlistbox连接数据库,该怎么解决

热度:7   发布时间:2016-04-29 06:49:50.0
dropdownlistbox连接数据库
string ls_temp
declare readdate dynamic cursor for sqlsa;
string ls_sql="select tuzhiname  from tuzhiinfo where userno=:sdf"
prepare sqlsa from :ls_sql;
open dynamic readdate;
do while sqlca.sqlcode=0
fetch readdate into:ls_temp;
if sqlca.sqlcode=0 then
    ddlb_1.additem(ls_temp)
end if
loop
ddlb_1.SelectItem(1)
close readdate;

求助大家,以上代码连接了ddlb,但是“select tuzhiname  from tuzhiinfo where userno=:sdf”
语句里的where条件里的":sdf"要怎样传进去。
ddlb

------解决方案--------------------

使用动态语法4(Dynamic SQL Format 4 SQL statement)

string Sqlstatement, sValue

Sqlstatement = "SELECT emp_fname, emp_lname " &

       + "FROM employee WHERE state = ?"

PREPARE SQLSA FROM :Sqlstatement ;

DESCRIBE SQLSA INTO SQLDA ;

// If the DESCRIBE is successful, the input

// descriptor array will contain one input

// descriptor that you must fill prior to the OPEN

DECLARE my_cursor DYNAMIC CURSOR FOR SQLSA ;

SetDynamicParm(SQLDA, 1, "MA")

OPEN DYNAMIC my_cursor USING DESCRIPTOR SQLDA ;

FETCH my_cursor USING DESCRIPTOR SQLDA ;
。。。。。。。。

但是这样的语句可读性差一些,不如使用 string ls_sql="select tuzhiname  from tuzhiinfo where userno='"+ls_sdf +"'" 组合好直接使用直接一些。


另:敬请关注TOPANY PB.NET框架

------解决方案--------------------
string ls_sdf //里面存你的参数
ls_sdf = "0001"

string ls_temp
declare readdate dynamic cursor for sqlsa;
string ls_sql="select tuzhiname  from tuzhiinfo where userno='" + ls_sdf + "'"
prepare sqlsa from :ls_sql;
open dynamic readdate;
do while sqlca.sqlcode=0
fetch readdate into:ls_temp;
if sqlca.sqlcode=0 then
    ddlb_1.additem(ls_temp)
end if
loop
ddlb_1.SelectItem(1)
close readdate;