标题:关于列前缀与查询中所用的表名或别名不匹配的问题
只看楼主
fish16402
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-26
 问题点数:0 回复次数:7 
关于列前缀与查询中所用的表名或别名不匹配的问题
做了一个VB连接SQL2000的程序,并运行SQL语句创建几个表,但运行的时候出现如下错误:
[Microsoft][ODBC sql server driver][sql server]列前缀't_icitemcore'与查询中所用的表名或列名不匹配。
我如果在服务器的SQL2000查询分析器中直接运行下面包含的SQL语句是没问题的,放到VB代码中就出现这个错误,请高手看看到底是哪里错了,是不是写错了,在线等,万分感谢!!
Private Sub Command1_Click()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
conn.C
conn.ConnectionTimeout = 30
conn.Open
rs.Open "select fitemid,fqty Into richard1 From iccustbomchild where finterid=(select finterid From icbom where fbomnumber='custbom000001')", conn, adOpenKeyset
rs.Open "select fnumber,fname,fmodel,fqty Into richard2 from t_ICItemCore innr join richard1 on t_ICItemCore.fitemid=richard1.fitemid", conn, adOpenKeyset
rs.Open "select finterid,fitemid,fqty Into richard3 From icbomchild where finterid in(select finterid From icbom where fitemid in(select fitemid From t_icitemcore where fnumber in(select fnumber From richard2 where fnumber like '2.%')))", conn, adOpenKeyset
rs.Open "select fnumber as 物料代码,fname as 物料名称,fmodel as 规格型号,fqty as 用量 Into richard4 from t_icitemcore inner join richard3 on t_icitemcore.fitemid=richard3.fitemid", conn, adOpenKeyset
rs.Open "select * from richard4"
Dim i As Long
Text1.Text = "物料编码" & "     -     " & "名称" & "     -     " & "规格型号" & "     -     " & vbCrLf
For i = 0 To rs.RecordCount - 1
    Text1.Text = Text1.Text & rs.Fields(0).Value & " - " & rs.Fields(1).Value & "      -      " & rs.Fields(2).Value & "      -      " & rs.Fields(3).Value & vbCrLf
    rs.MoveNext
Next
rs.Close
End Sub
搜索更多相关主题的帖子: 表名 前缀 别名 SQL 服务器 
2007-11-26 22:31
fish16402
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-26
得分:0 
顶一下,高手指点一下啊,我这是想把多条SQL语句在VB中执行,可能是语法错误,就是不知道错在哪里,在网上搜索也找不到相关的帖子!
2007-11-27 08:20
XieLi
Rank: 1
等 级:新手上路
威 望:1
帖 子:762
专家分:0
注 册:2007-7-24
得分:0 
一个过程的记录集变量不能在同一事件时打开多个记录,必须关闭记录集,再打开下一个.否则会出错的.

conn.Open 打开什么,连接字符串吧.

拥有蓝天的白云,拥有你的我.
2007-11-27 08:24
fish16402
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-26
得分:0 
说句实话,我现在还没理解conn.open和rs.open的意思,能不能解释下这两个命令后面都带什么啊,还有如果我要在VB里面运行多个SQL语句,我该怎么做,高手帮我改一下吧,昨天弄了一个晚上,我真是不知道怎么弄了!!
2007-11-27 08:36
XieLi
Rank: 1
等 级:新手上路
威 望:1
帖 子:762
专家分:0
注 册:2007-7-24
得分:0 
[url]http://bbs.[/url]

看一下上面的,就知道
conn.open是打开什么,

要执行多个SQL语句,就多声明几个记录集.

拥有蓝天的白云,拥有你的我.
2007-11-27 08:57
fish16402
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-26
得分:0 
Private Sub Command1_Click()
Set conn = New ADODB.Connection
Set conn1 = New ADODB.Connection
Set conn2 = New ADODB.Connection
Set conn3 = New ADODB.Connection
Set rs = New ADODB.Recordset
Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs1.CursorLocation = adUseClient
rs2.CursorLocation = adUseClient
rs3.CursorLocation = adUseClient
conn.ConnectionString = "driver={sql server};server=10.1.8.181;uid=sa;pwd=sa;database=ais20071122144144"
conn1.ConnectionString = "driver={sql server};server=10.1.8.181;uid=sa;pwd=sa;database=ais20071122144144"
conn2.ConnectionString = "driver={sql server};server=10.1.8.181;uid=sa;pwd=sa;database=ais20071122144144"
conn3.ConnectionString = "driver={sql server};server=10.1.8.181;uid=sa;pwd=sa;database=ais20071122144144"
conn.ConnectionTimeout = 30
conn1.ConnectionTimeout = 30
conn2.ConnectionTimeout = 30
conn3.ConnectionTimeout = 30
conn.Open
rs.Open "select fitemid,fqty Into richard1 From iccustbomchild where finterid=(select finterid From icbom where fbomnumber='custbom000001')", conn, adOpenKeyset
rs.Close
conn.Close
conn1.Open
rs1.Open "select fnumber,fname,fmodel,fqty Into richard2 from t_ICItemCore innr join richard1 on t_ICItemCore.fitemid=richard1.fitemid", conn, adOpenKeyset
End Sub
我改了一下,代码如上,但还是不行,我确实没理解这几段话的意思,能不能帮我看看是错在哪里,原理到底是什么,万分感谢!!
2007-11-27 09:43
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
这么多Connection?..晕

我的msn: myfend@
2007-11-27 09:54
XieLi
Rank: 1
等 级:新手上路
威 望:1
帖 子:762
专家分:0
注 册:2007-7-24
得分:0 
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set rs1 = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs1.CursorLocation = adUseClient
rs2.CursorLocation = adUseClient
rs3.CursorLocation = adUseClient
conn.ConnectionString = "driver={sql server};server=10.1.8.181;uid=sa;pwd=sa;database=ais20071122144144"
conn.ConnectionTimeout = 30
conn.Open
rs.Open "select fitemid,fqty Into richard1 From iccustbomchild where finterid=(select finterid From icbom where fbomnumber='custbom000001')", conn, adOpenKeyset
rs1.Open "select fnumber,fname,fmodel,fqty Into richard2 from t_ICItemCore innr join richard1 on t_ICItemCore.fitemid=richard1.fitemid", conn, adOpenKeyset

拥有蓝天的白云,拥有你的我.
2007-11-27 10:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-188618-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.279086 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved