积极答复者
sql插入平均值的问题

问题
-
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = conn
.Open "select avg(phy) as ach from tableaa"
.Open "insert into tableaa(phy) values(''&ach&'')"
提示出错信息:
run-time error '3705'
operation is not allowed when the object is open
- 已编辑 Honny_yeyh 2012年1月20日 9:16
答案
-
你需要把数据读出来 http://msdn.microsoft.com/en-us/library/bb177501(v=office.12).aspx
另外,你可以用一条sql语句一起执行:
Insert into tableaa(phy) values select avg(phy) as ach from tableaa
另外VB6的问题请follow这个帖子:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:37
-
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36
-
为什么 你不合并成一行执行呢?
当你分两次执行的时候,第二次的recordset找不到它曾经用过的变量啊,要不然你就这样:
ach1 = rst("ach")
MsgBox ach1 //here right
With rst1
.ActiveConnection = conn
.Open "Insert into tableaa values ('cy00bb','aavb','mmm', “ & ach1 & ” ,'0','12','12','9','9')"
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36
-
Dim ach As Integer
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.JET.OLEDB.4.0"
.Open "c:\yyiblio.mdb"
End With
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
With rst
.ActiveConnection = conn
.Open "select avg(phy) as ach from tableaa"
MsgBox ach '这里提示ach为0- 已标记为答案 Honny_yeyh 2012年1月20日 11:37
-
不好意思 我写错了
Insert into tableaa (phy)
select avg(phy) as achhh from tableaa
没有Values
新年快乐!
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36
全部回复
-
声明两个不同变量名称的ADODB.Recordset
再各自Open试试看
- The blog of typewriter職人
- Convert C# to VB.NET
- /*If my concept is wrong ,please correct me.Thanks.*/
-
Dim ach As Integer
Set conn = New ADODB.Connection
With conn
' Set the OleDB provider for the connection.
.Provider = "Microsoft.JET.OLEDB.4.0"
' Open a connection to Northwind.mdb.
.Open "c:\yyiblio.mdb"
End With
'select AVG(A) as Aavg,AVG(B) as Bavg from table
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
With rst
.ActiveConnection = conn
.Open "select avg(phy) as ach from tableaa" '这里没有起到作用, ach=0End With
With rst1
.ActiveConnection = conn.Open "insert into tableaa(phy) values(' " & ach & " ')"
End With
- 已编辑 Honny_yeyh 2012年1月17日 9:36
- 已标记为答案 Honny_yeyh 2012年1月20日 11:37
- 取消答案标记 Honny_yeyh 2012年1月20日 11:37
-
-
Dim ach As Integer
Set conn = New ADODB.Connection
With conn
.Provider = "Microsoft.JET.OLEDB.4.0"
.Open "c:\yyiblio.mdb"
End With
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
With rst
.ActiveConnection = conn
.Open "select avg(phy) as ach from tableaa"
MsgBox ach '这里提示ach为0- 已标记为答案 Honny_yeyh 2012年1月20日 11:37
-
你需要把数据读出来 http://msdn.microsoft.com/en-us/library/bb177501(v=office.12).aspx
另外,你可以用一条sql语句一起执行:
Insert into tableaa(phy) values select avg(phy) as ach from tableaa
另外VB6的问题请follow这个帖子:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:37
-
ach1 = rst("ach")
MsgBox ach1 //here right
With rst1
.ActiveConnection = conn
.Open "Insert into tableaa values ('cy00bb','aavb','mmm', &ach1 ,'0','12','12','9','9')" //here mistake
- 已编辑 Honny_yeyh 2012年1月20日 8:08
-
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36
-
为什么 你不合并成一行执行呢?
当你分两次执行的时候,第二次的recordset找不到它曾经用过的变量啊,要不然你就这样:
ach1 = rst("ach")
MsgBox ach1 //here right
With rst1
.ActiveConnection = conn
.Open "Insert into tableaa values ('cy00bb','aavb','mmm', “ & ach1 & ” ,'0','12','12','9','9')"
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 9:08
- 取消答案标记 Honny_yeyh 2012年1月20日 9:14
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36
-
你需要把数据读出来 http://msdn.microsoft.com/en-us/library/bb177501(v=office.12).aspx
另外,你可以用一条sql语句一起执行:
Insert into tableaa(phy) values select avg(phy) as ach from tableaa
另外VB6的问题请follow这个帖子:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
.Open " Insert into tableaa (phy) values select avg(phy) as achhh from tableaa"
提示 syntax error in INSERT INTO statement.
可以这样吗:.Open " Insert into tableaa (phy) values select avg(phy) from tableaa"
- 已编辑 Honny_yeyh 2012年1月20日 9:17
-
不好意思 我写错了
Insert into tableaa (phy)
select avg(phy) as achhh from tableaa
没有Values
新年快乐!
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Honny_yeyh 2012年1月20日 11:36