关于新建和删除表

csdncsdncsdn 2002-12-11 08:39:12
我通过ODBC连库,现在想让用户从界面定义表的名称,
各列的属性,然后在数据库中相应的新建一个表
怎样做到?删除一个表又该怎么做呐?
...全文
27 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
ldy,谢谢你了
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
搞定了,牢骚刚发完
再弄一次,居然通过了,
看来这玩意还得多弄才行,要不然对不起各位的帮助,
顺便问一句,你们也是一天到晚上网的虫吗?
==回去了
==晚安==
===真理的获得过程==
实践->郁闷->再实践->再郁闷->happytonight
dotnba 2002-12-12
  • 打赏
  • 举报
回复
string tablename="dd"

SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=false
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

// Connect to the database.
CONNECT USING SQLCA;

ls_sql="drop table "+tablename
execute immediate :ls_sql;

if SQLCA.SQLCode=0 then
MessageBox("提示","删除成功")
Commit;
else
MessageBox("提示","删除失败")
RollBack;
end if
dotnba 2002-12-12
  • 打赏
  • 举报
回复
SQLCA.AutoCommit=true
去掉
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
====无可奈何删不掉===
string tablename="dd"

SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=false
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

// Connect to the database.
CONNECT USING SQLCA;

SQLCA.AutoCommit=true

ls_sql="drop table "+tablename
execute immediate :ls_sql;
if SQLCA.SQLCode=0 then
COMMIT;
MessageBox("提示","删除成功")
else
MessageBox("提示","删除失败")
end if

SQLCA.AutoCommit=False



===或者===
string tablename="dd"

SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=false
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

// Connect to the database.
CONNECT USING SQLCA;

ls_sql="drop table "+tablename
execute immediate :ls_sql;

COMMIT;

if SQLCA.SQLCode=0 then
MessageBox("提示","删除成功")
else
MessageBox("提示","删除失败")
end if

SQLCA.AutoCommit=False
======或者
string tablename="dd"

SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=false
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

// Connect to the database.
CONNECT USING SQLCA;
SQLCA.AutoCommit=true

ls_sql="drop table "+tablename
execute immediate :ls_sql;

COMMIT;

if SQLCA.SQLCode=0 then
MessageBox("提示","删除成功")
else
MessageBox("提示","删除失败")
end if

SQLCA.AutoCommit=False
=========
翠花,我做不出来呀,走咧,伤自尊
GOODSTART 2002-12-12
  • 打赏
  • 举报
回复
EXECUTE IMMEDIATE "drop test";
if sqlca.sqlcode = 0 then
commit;
end if
dotnba 2002-12-12
  • 打赏
  • 举报
回复
csdncsdncsdn(纳兰容若) :
我试了。没问题啊!
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
我高兴得太早了,原来是提示显示成功,但表还在!郁闷
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
删除成功,谢谢大家出手相助^_^
dotnba 2002-12-12
  • 打赏
  • 举报
回复
EXECUTE IMMEDIATE "drop table test";
if sqlca.sqlcode = 0 then
commit;
end if
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
888888888888(888888888888)
把commit去掉直接结束;
是可以,但是查了一下数据库,
表并没有删掉呀?
888888888888 2002-12-12
  • 打赏
  • 举报
回复
把commit去掉直接结束;
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
我原来贴的就是SQLCA.AutoCommit=False呀,
SilverSands(洞庭浪子)
加个commit后编译都出错呀
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
===renmao(晓晓) ==
试了一次。不行呀!!!
SilverSands 2002-12-12
  • 打赏
  • 举报
回复
还没完成革命那,再接再厉,呵呵!
SilverSands 2002-12-12
  • 打赏
  • 举报
回复
先将SQLCA.AutoCommit=False,然后在Exec后加个commit;试过么?
renmao 2002-12-12
  • 打赏
  • 举报
回复
string tablename="dd"
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=true
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

SQLCA.AutoCommit=true//加
// Connect to the database.
CONNECT USING SQLCA;

ls_sql="drop "+tablename
execute immediate :ls_sql;

if SQLCA.SQLCode=0 then
MessageBox("提示","删除成功")
else
MessageBox("提示","删除失败")
end if

SQLCA.AutoCommit=False

试试刊
csdncsdncsdn 2002-12-12
  • 打赏
  • 举报
回复
这样删除表为什么说不对呀

string tablename="dd"
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit=true
SQLCA.DBParm = "ConnectString='DSN=east;UID=east;PWD=east'"

// Connect to the database.
CONNECT USING SQLCA;

ls_sql="drop "+tablename
execute immediate :ls_sql;

if SQLCA.SQLCode=0 then
MessageBox("提示","删除成功")
else
MessageBox("提示","删除失败")
end if

SQLCA.AutoCommit=False
dotnba 2002-12-11
  • 打赏
  • 举报
回复
select count(id) into :li_exist
from sysobjects
where id = object_id("bundle") and
OBJECTPROPERTY(id,'IsUserTable') = 1;
if li_exist = 0 then
ls_create = "create table bundle " + &
"( " + &
" bundle_id char(6) not null, " + &
" mt_code char(3) null default '424', " + &
" manu_date datetime null, " + &
" bundle_weight numeric(19,6) null, " + &
" uo2_weight numeric(19,6) null, " + &
" elem_iso_type char(1) null default 'N', " + &
" q_percent numeric(19,6) null, " + &
" elem_iso_code char(1) null, " + &
" t_percent numeric(19,6) null, " + &
" transact_mem varchar(10) null, " + &
" check_mem varchar(10) null, " + &
" approve_mem varchar(10) null, " + &
" unit varchar(4) null, " + &
" manufacturer varchar(30) null default '中国核工业集团公司二Ο二厂', " + &
" if_print smallint null default 0, " + &
" constraint bundle_key primary key nonclustered (bundle_id) " + &
")"
EXECUTE IMMEDIATE :ls_create;
if sqlca.sqlcode <> 0 then
rollback;
return false
end if
ls_create = "create unique index bundle_PKindex on bundle(bundle_id)"
EXECUTE IMMEDIATE :ls_create;
if sqlca.sqlcode <> 0 then
rollback;
return false
end if
end if
wonder01 2002-12-11
  • 打赏
  • 举报
回复
楼上这位仁兄说的没错,就是先把你执行的创建或是删除表的sql语句拼成字符串ls_sql。然后在execute immediate :ls_sql执行,还有点很重要,一定要commit;
加载更多回复(2)

611

社区成员

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

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