"select * insert into sjyl from ylyysj where bh=" & inttjbh

解决方案 »

  1.   

    insert sjy1 select* from y1yysj where bh=" & inttjbh & "
      

  2.   

    "select * insert into sjyl from ylyysj where bh=" & inttjbh
    楼上说的是产生一个新表你两张表的字段是否是一样,假如不一样,就会产生错误
      

  3.   


    insert table_name select * from table_list where search_condition
    非常符合语法,你是不是插入到别的表中了
    你试一下直接往表中插入,是否能行
      

  4.   

    where bh=" & inttjbh是不是条件错了,要不要加单引号。
      

  5.   

    cnn1.Execute "insert into sjyl select * from ylyysj where ylyysj.bh=" & inttjbh
      

  6.   

    cnn1.Execute "insert into sjyl ()  《----------这里是不是需要放入你表中的字段select * from ylyysj where bh=" & inttjbh
    一般形式的添加:
    insert into 表名 (字段1,字段2、、、、) values(值1,值2、、、、)不知道这样说对不对
    仅供参考
      

  7.   

    SQL吗?"select * into sjyl from ylyysj where bh=" & inttjbh如果bh是char型"select * into sjyl from ylyysj where bh='" & inttjbh & "'"
      

  8.   

    前提必须是sjyl表不存在,才可以用select * into 表
    否则只能用insert into 表 (字段列表) values (值列表) 来插入数据
    可以用drop table 表名 来删除表
      

  9.   

    to luccy:
    cnn1.Execute "insert into sjyl select * from ylyysj where ylyysj.bh=" & inttjbh
    ...
    也不行。
    to xinshou1979330:
    因为sjyl与ylyysj两个表的结构完全一样,我想用不着写字段;另要是写出字段
    很不好,因为我的表的字段有180多个。还有你说的那个形式是用在单纪录添加方面。
    谁能想出原因何在?我想是不是cnn1不更新方面的问题?
      

  10.   

    注意inttjbh的类型,若为int型请用cstr(inttjbh),然后字段一样的话该没问题
      

  11.   

    建议你把字段都写出来
    cnn1.Execute "insert into sjyl() select ...... from ylyysj where ylyysj.bh=" & inttjbh
      

  12.   

    to stou2000:无法规范呀!是原料的营养成份,不能少一个呀。。
    to online:字段写了也不行。
    to bejon:变成cstr(inttjbh)也不能完成添加
    那位知道根子原因呀!!
      

  13.   

    public rs as new adodb.recordsetpublic cmd as new adodb.commandcmd.commandtext="inset into sjyl select * from ylyysj where ylyysj.bh="set rs=cmd.execute
      

  14.   

    to xks:你的方法还是不能完成添加。
    我想是不是该想些关于insert into语句的使用条件,比如要用的表sjyl在添加时不能同时让另一个记录集打开,是不是应处于关闭状态才能完成添加?可是当我试着已经关闭了建立在sjyl上的所有记录集后,再用本语句还是不能完成添加。唉,怎么办?!!!谁能解决?
      

  15.   

    我觉得怎么也是没有用refresh或者是update啊
      

  16.   

    to buff : 我的表里没有自动增加的字段。
      

  17.   

    ylyysj 和 inttjbh 这两个表的结构是一样的话,那要看插入的这个纪录所在的关键字的数值在ylyysj中存不存在,如果存在当然插入失败
      你可以在sql server  7.0/2000中的 Sql Query Analyzer 中写sql语句测试一下
      如果有错误,它会徽给你提示信息
      

  18.   

    to springflying:我的两个表是ylyysj与sjyl,inttjbh是一个变量。我的目的是从表ylyysj里面取出一条编号符合‘编号=inttjbh“的记录来,添加到表sjyl中去。由于我的这两个表的结构是一模一样的。并且字段多达180多个。所以我就想用
    INSERT INTO target [IN externaldatabase][(field1[,field2[,...]])] SELECT [source.]field1[,field2[,...] FROM tableexpression 这种结构。并且我的表sjyl中确实没有表ylyysj的记录。
      

  19.   

    to fishmans:没有相同记录。主键是有。但我保证没有重复记录。
    to xlyt:没有用事务。
    谢谢大家。问题到现在找不出原因来。很不爽。我的要求是:
    我的目的是从表ylyysj里面取出一条编号符合‘编号=inttjbh“的记录来,添加到表sjyl中去。由于我的这两个表的结构是一模一样的。并且字段多达180多个。所以我就想用
    INSERT INTO target [IN externaldatabase][(field1[,field2[,...]])] SELECT [source.]field1[,field2[,...] FROM tableexpression 这种结构。并且我的表sjyl中确实没有表ylyysj的记录。
    该如何是好?
      

  20.   

    这个问题可以通过调试发现错误的
      首先你可以在sql server 20000中的Sql Query Analyzer 中写sql语句测试
      USE  所用数据库名
      DECLARE @sn int   --sn的类型与bh字段的类型相同,我这儿把他当作整型,当然也可以是字符型
      SELECT  @sn = 这个值为你想插入的那个编号的值用常数,直接从数据库找出因为这是测试
      insert into sjyl select * from ylyysj where bh= @sn
      如果成功,说明有可能错误是你在vb中定义的inttjbh的类型与bh字段的类型不符,或者是
    inttjbh 的值不与你的bh字段的值相等,你可以在
     1  Dim inttjbh As Integer
     2 inttjbh = rstcnn5!bh
     3 cnn1.Execute "insert into sjyl select * from ylyysj where bh=" & inttjbh
     4  rstcnn6.Requery3处设断点,看看inttjbh的值是不是与你所要插入的值相同,如果inttjbh是字符串,要注意去掉空格,这样可能会找出错误所在