请问如何规定输入内容不能为空?

furyrain 2003-04-25 12:57:18
在数据窗口中,假设现在在最后一列添加一条空记录,并要求输入新内容.
假设现在有“学号”列,如何实现学号的输入不能为空呢?
...全文
267 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
th820901 2003-04-29
  • 打赏
  • 举报
回复
up
zhoufenghubei 2003-04-29
  • 打赏
  • 举报
回复
用dw_1.FINDREQUIRED()函数来检测。本函数只能和datawindow控件一起使用。函数具体用法如下:
Reports the next row and column that is required and contains a NULL value. The method arguments that specify where to start searching also store the results of the search. You can speed up the search by specifying that FindRequired check only inserted and modified rows.
例子如下:
long ll_row = 1

string ls_colname, ls_textname

// Make sure the last entry is accepted

IF adw_control.AcceptText() = -1 THEN

adw_control.SetFocus()

RETURN -2

END IF

// Find the first empty row and column, if any

IF adw_control.FindRequired(Primary!, ll_row, &

li_colnbr, ls_colname, true) < 1 THEN

//If search fails due to error, then return

RETURN -2

END IF

// Was any row found?

IF ll_row <> 0 THEN

// Get the text of that column's label.

ls_textname = ls_colname + "_t.Text"

ls_colname = adw_control.Describe(ls_textname)

// Tell the user which column to fill in

MessageBox("Required Value Missing", &

"Please enter a value for '" &

+ ls_colname + "', row " &

+ String(ll_row) + ".", &

StopSign! )

// Make the problem column current.

adw_control.SetColumn(li_colnbr)

adw_control.ScrollToRow(ll_row)

adw_control.SetFocus()

RETURN -1

END IF

// Return success code if all required

// rows and columns have data

RETURN 1
heihuo4701 2003-04-29
  • 打赏
  • 举报
回复
PBsystem(我学PB)
的说法我同意,但是,我用过一次,PB8+SqlServer2000 好像没有反应呀。
能不能给点题示?



// ### C# C++ VB.NET ASP.NET

高山流水,知音难觅 !

Nothing is imposible for a willing heart !
heihuo4701 2003-04-29
  • 打赏
  • 举报
回复
我查了: 数据窗口字段有一个 Required 属性,选用就可以了。呵呵



// ### C# C++ VB.NET ASP.NET

高山流水,知音难觅 !

Nothing is imposible for a willing heart !
PBsystem 2003-04-28
  • 打赏
  • 举报
回复
你们才是编程水平不行
用户输入界面不要设置这样死,
应在数据库中设置不为空,输入界面不管
在dberror()即保存失败中判断
dbsqlcoder在每个数据库中返回值不一样,代表保存出错的不同原因
lvjunyu 2003-04-28
  • 打赏
  • 举报
回复
heihuo4701(blue) ,虽然你的想法不错,但是可以看得出来,你是有编过程序,但是经验还是不足的,losefocus这个事件首先拼写错误,然后这个事件是无法知道你修改的是哪个字段,认真学习吧
cooltnt 2003-04-27
  • 打赏
  • 举报
回复
同意楼上的楼上[ lvjunyu(天翔) ],呵呵。
oyj 2003-04-27
  • 打赏
  • 举报
回复
同意楼上
lvjunyu 2003-04-27
  • 打赏
  • 举报
回复
假设学号字段名称为cardid,在数据窗口的itemchanged事件中写:
string ls_cardid
accepttext()
if dwo.name = 'cardid' then
ls_cardid = string(data)
if isnull(ls_cardid) or ls_cardid = '' then
messagebox('提示','学号不能为空,请重新输入学号')
return 1
end if
end if
heihuo4701 2003-04-27
  • 打赏
  • 举报
回复
有没有 Lostfouc 事件呀,在里面写代码判断以下就可以了



// ### C# C++ VB.NET ASP.NET

高山流水,知音难觅 !

Nothing is imposible for a willing heart !
furyrain 2003-04-27
  • 打赏
  • 举报
回复
对不起,我没有说清楚。
在这里我再补充一下,就是说现在在数据窗口中添加一条新记录,
新记录包含很多字段,我想实现的是假如在“学号”这一行没有输入任何内容就按了tab键,
或者把鼠标移到了下一行,就立刻弹出对话框提示说“学号”不能为空。
请问如何实现呢?
tchatcha 2003-04-26
  • 打赏
  • 举报
回复
ls_htmc=dw_1.getitemstring(dw_1.getrow(),'htmc')
if ls_htmc='' or isnull(ls_htmc) then //判断htmc是否为空
messagebox('提示信息','请输入合同名称!') //提示
dw_1.setfocus()
dw_1.setcolumn('htmc') //焦点返回
return //中断操作
end if
schen23 2003-04-25
  • 打赏
  • 举报
回复
例:
保存时

ls_htmc=dw_1.getitemstring(dw_1.getrow(),'htmc')
if ls_htmc='' or isnull(ls_htmc) then //判断htmc是否为空
messagebox('提示信息','请输入合同名称!') //提示
dw_1.setfocus()
dw_1.setcolumn('htmc') //焦点返回
return //中断操作
end if


能看懂吗?
xdhis 2003-04-25
  • 打赏
  • 举报
回复
楼上说得对!
huangxinru 2003-04-25
  • 打赏
  • 举报
回复
保存时判断
Cat 2003-04-25
  • 打赏
  • 举报
回复
定义数据库时,设置“学号”不能为NULL

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧