vb执行sql语句
我想在VB里打开数据库然后执行SQL语句计算一段时间内数据的方差值useB02selectVAR(b02a_atp1_ia)asb02a_atp1_iafromdbo.B...
我想在VB里打开数据库 然后执行SQL语句 计算一段时间内数据的方差值
use B02
select VAR(b02a_atp1_ia) as b02a_atp1_ia
from dbo.B02A_ATP1
where [time] between ('2008-10-10 9:16:52') And ('2008-10-10 9:56:52')
go
上面是SQL语句 B02是数据库名 dbo.B02A_ATP1是表名b02a_atp1_ia是字段名我该怎么做呢? 展开
use B02
select VAR(b02a_atp1_ia) as b02a_atp1_ia
from dbo.B02A_ATP1
where [time] between ('2008-10-10 9:16:52') And ('2008-10-10 9:56:52')
go
上面是SQL语句 B02是数据库名 dbo.B02A_ATP1是表名b02a_atp1_ia是字段名我该怎么做呢? 展开
1个回答
展开全部
首先引用
microsoft activex data objects 2.8 library
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.Command
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" & "User ID=sa;PassWord=你数据库密码;Initial Catalog=数据库名"
conn.Open
cmd.ActiveConnection = conn '使用命令对象方法
cmd.CommandText = "select VAR(b02a_atp1_ia) as b02a_atp1_ia
from dbo.B02A_ATP1
where [time] between ('2008-10-10 9:16:52') And ('2008-10-10 9:56:52')"
Set rst = cmd.Execute
microsoft activex data objects 2.8 library
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.Command
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" & "User ID=sa;PassWord=你数据库密码;Initial Catalog=数据库名"
conn.Open
cmd.ActiveConnection = conn '使用命令对象方法
cmd.CommandText = "select VAR(b02a_atp1_ia) as b02a_atp1_ia
from dbo.B02A_ATP1
where [time] between ('2008-10-10 9:16:52') And ('2008-10-10 9:56:52')"
Set rst = cmd.Execute
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询