目的是想在datawindow里面显示 自己写的SQL语句查询的结果,语句里面是有变量的。
看了网上介绍说 syntaxfromsql() 可以实现,试了一下:
1.建了一个datawindow dw_1,dataobject 为空。
2.添加一个按钮,clicked()时间写入如下代码:
string ERRORS,ERRORS1, sql_syntax
string presentation_str, dwsyntax_str
sql_syntax = "SELECT c_no,c_name,c_bdate,c_edate " &
+ "from pt_info " &
+ "WHERE c_bdate>='"+startdate+"' and c_edate<'"+enddate+"' "
presentation_str = "style(type=grid)"
dwsyntax_str = SQLCA.SyntaxFromSQL(sql_syntax, presentation_str, ERRORS)
IF Len(ERRORS) > 0 THEN
MessageBox("Caution", "SyntaxFromSQL caused these errors: " + ERRORS)
RETURN
END IF
dw_1.CREATE( dwsyntax_str, ERRORS1)
IF Len(ERRORS1) > 0 THEN
MessageBox("Caution", "Create cause these errors: " + ERRORS1)
RETURN
END IF
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
然后运行 ,点击按钮,datawindow 由白变灰,然后啥也没有显示,这到底什么情况啊?
百度了很多,都没有这方面的说明,是不是这样的用法?datawindow数据源dataobject是否需要设置?
请赐教~
------解决方案--------------------
肯定要出错了,问题在日期上,你这样先试试
string ERRORS,ERRORS1, sql_syntax
string presentation_str, dwsyntax_str
sql_syntax = "SELECT c_no,c_name,c_bdate,c_edate " &
+ "from pt_info "
presentation_str = "style(type=grid)"
dwsyntax_str = SQLCA.SyntaxFromSQL(sql_syntax, presentation_str, ERRORS)
IF Len(ERRORS) > 0 THEN
MessageBox("Caution", "SyntaxFromSQL caused these errors: " + ERRORS)
RETURN
END IF
dw_1.CREATE( dwsyntax_str, ERRORS1)
IF Len(ERRORS1) > 0 THEN
MessageBox("Caution", "Create cause these errors: " + ERRORS1)
RETURN
END IF
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
------解决方案--------------------
需要与sql里的日期匹配起来,如果是oracle可以这么写
string ERRORS,ERRORS1, sql_syntax
string presentation_str, dwsyntax_str
//前提是startdate和enddate为YYYY-MM-DD日期格式的字符串
sql_syntax = "SELECT c_no,c_name,c_bdate,c_edate " &
+ "from pt_info " &
+ "WHERE c_bdate>=to_date('"+startdate+"','YYYY-MM-DD') and c_edate<to_date('"+enddate+"','YYYY-MM-DD') "
presentation_str = "style(type=grid)"
dwsyntax_str = SQLCA.SyntaxFromSQL(sql_syntax, presentation_str, ERRORS)
IF Len(ERRORS) > 0 THEN
MessageBox("Caution", "SyntaxFromSQL caused these errors: " + ERRORS)
RETURN
END IF
dw_1.CREATE( dwsyntax_str, ERRORS1)
IF Len(ERRORS1) > 0 THEN
MessageBox("Caution", "Create cause these errors: " + ERRORS1)
RETURN
END IF
dw_1.SetTransObject(SQLCA)
dw_1.Retrieve()
------解决方案--------------------
如果sqlserver和sybase的数据可以用convert转换一下,问题就出在日期上了