VB系统提示Refresh方法的IAdodc方法失败
代码是这样的:PrivateSubCmdReturn_Click()UnloadMeEndSubPrivateSubForm_Load()DimstrCnoAsStrin...
代码是这样的:
Private Sub CmdReturn_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim strCno As String
Dim strSelect As String
strCno = Trim(Form1.TxtCno.Text)
strSelect = "select Cname,Gname,Gprice,Ono from Customer c join Order " _
& "on c.Cno=Order.Cno join Goods g on g.Gno=Order.Gno where " _
& "Order.Cno='" & strCno & " ' "
AdodcGrid.CommandType = adCmdText
AdodcGrid.RecordSource = strSelect
AdodcGrid.Refresh
Set DtgCond.DataSource = AdodcGrid
Call InitGrid
End Sub
Private Sub InitGrid()
With DtgCond
.Columns(0).Caption = "客户姓名"
.Columns(1).Caption = "商品名称"
.Columns(2).Caption = "商品价格"
.Columns(3).Caption = "订单编号"
.Columns(0).Width = 1000
.Columns(1).Width = 2000
.Columns(2).Width = 800
.Columns(3).Width = 800
End With
End Sub
错误的部分应该是中间那一部分,Private Sub Form_Load()及其下面那段。。但不解啊 展开
Private Sub CmdReturn_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim strCno As String
Dim strSelect As String
strCno = Trim(Form1.TxtCno.Text)
strSelect = "select Cname,Gname,Gprice,Ono from Customer c join Order " _
& "on c.Cno=Order.Cno join Goods g on g.Gno=Order.Gno where " _
& "Order.Cno='" & strCno & " ' "
AdodcGrid.CommandType = adCmdText
AdodcGrid.RecordSource = strSelect
AdodcGrid.Refresh
Set DtgCond.DataSource = AdodcGrid
Call InitGrid
End Sub
Private Sub InitGrid()
With DtgCond
.Columns(0).Caption = "客户姓名"
.Columns(1).Caption = "商品名称"
.Columns(2).Caption = "商品价格"
.Columns(3).Caption = "订单编号"
.Columns(0).Width = 1000
.Columns(1).Width = 2000
.Columns(2).Width = 800
.Columns(3).Width = 800
End With
End Sub
错误的部分应该是中间那一部分,Private Sub Form_Load()及其下面那段。。但不解啊 展开
1个回答
展开全部
"select Cname,Gname,Gprice,Ono from Customer c join Order " _ 中的Customer c是什么意思?,可能不需要Customer吧。
如果是Access数据库,前一个 join 部分要打括号的,
如: ... From (表1 join 表2 on 表1.id=表2.id) join 表3 on 表1.id=表3.id
另外From前面的字段列表最好明确表名
如果是Access数据库,前一个 join 部分要打括号的,
如: ... From (表1 join 表2 on 表1.id=表2.id) join 表3 on 表1.id=表3.id
另外From前面的字段列表最好明确表名
追问
连的是sql数据库,这个数据库有3个表,分别是Customer(客户),Order(订单),Goods(商品),其中Customer的主键是Cno,Goods的主键是Gno,然后Order的主键是Cno和Gno(外键)
追答
from Customer c join Order " _
& "on c.Cno=Order.Cno join Goods g on g.Gno=Order.Gno where " _
& "Order.Cno='" & strCno & " ' "
那就是c多余的,还有Goods怎么也多了个g,是别名吗,我也不懂。把它去掉吧:
select * from Customer join Order " _
& "on Customer.Cno=Order.Cno join Goods on Goods.Gno=Order.Gno where " _
& "Order.Cno='" & strCno & "'"
试一下,能过的话* 号再改为字段名系列,要前缀表名。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询