| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 565 人关注过本帖
标题:access数据库查询问题
只看楼主 加入收藏
beelin2011
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-11-18
结帖率:0
收藏
已结贴  问题点数:0 回复次数:1 
access数据库查询问题
现在问题是:如何通过用产品名称,带出产品代码和厂家名称?以上二处代码如何修改,谢谢!


ElseIf MSH2.Col = 5 Then
   Dim rs As New ADODB.Recordset
    Call newCnOpen(cnn)
    rs.Open "select 厂家名称,产品代码 from 数据库表 where 产品名称=" & Combo1.Text, cnn, 3, 3

    Combo1.Clear
    If rs.RecordCount > 0 Then
    MSH2.TextMatrix(MSH2.Row, 5) = Combo1.Text
    MSH2.TextMatrix(MSH2.Row, 9) = rs("厂家名称")
    rs.Close: Set rs = Nothing
    Call closeCn
    End If

    Combo1.Text = ""
    Combo1.Visible = False

Private Sub msh2_click()
    ElseIf MSH2.Col = 5 Then
        Combo1.Clear
        Combo1.Text = MSH2.TextMatrix(MSH2.Row, 5)
        Combo1.Move MSH2.CellLeft, MSH2.CellTop, MSH2.CellWidth + 500     ', MSH2.CellHeight
        
    '    Combo1.Visible = True
        Dim rs As New ADODB.Recordset
        Call newCnOpen(cnn)
        rs.Open "select 产品名称 from 数据库表 where 产品代码='" & MSH2.TextMatrix(MSH2.Row, 2) & "'group by 产品名称", cnn, 1, 1
        If rs.RecordCount > 0 Then
        Do While Not rs.EOF
        Combo1.AddItem rs("产品名称")
        rs.MoveNext
        Loop
        rs.Close: Set rs = Nothing
        Call closeCn
        End If
        
        Combo1.Visible = True
        Combo1.SetFocus
    ElseIf MSH2.Col = 20 Then
    T1.Text = MSH2.TextMatrix(MSH2.Row, MSH2.Col)
    T1.Move MSH2.CellLeft, MSH2.CellTop, MSH2.CellWidth, MSH2.CellHeight
    T1.BackColor = RGB(222, 222, 222)
    T1.Visible = True
    T1.SetFocus
    End If
End If
MSH2.Refresh
Call ProcessMessages(MSH2)
End Sub

搜索更多相关主题的帖子: 产品 如何 数据库查询 数据库表 access 
2011-11-18 13:10
apple0072011
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:249
专家分:989
注 册:2011-8-17
收藏
得分:20 
ElseIf MSH2.Col = 5 Then
   Dim rs As New ADODB.Recordset
    Call newCnOpen(cnn)
    rs.Open "select 厂家名称,产品代码 from 数据库表 where 产品名称=" & Combo1.Text, cnn, 3, 3
改为:rs.Open "select 厂家名称,产品代码 from 数据库表 where 产品名称='" & COmbo1.Text & " ', cnn, 3, 3

    Combo1.Clear  删除该行
    If rs.RecordCount > 0 Then
    MSH2.TextMatrix(MSH2.Row, 5) = Combo1.Text
    MSH2.TextMatrix(MSH2.Row, 9) = rs("厂家名称")
    rs.Close: Set rs = Nothing
    Call closeCn
    End If

    Combo1.Text = ""
    Combo1.Visible = False

Private Sub msh2_click()
    ElseIf MSH2.Col = 5 Then
        Combo1.Clear
        Combo1.Text = MSH2.TextMatrix(MSH2.Row, 5)
        Combo1.Move MSH2.CellLeft, MSH2.CellTop, MSH2.CellWidth + 500     ', MSH2.CellHeight
        
    '    Combo1.Visible = True
        Dim rs As New ADODB.Recordset
        Call newCnOpen(cnn)
        rs.Open "select 产品名称 from 数据库表 where 产品代码='" & MSH2.TextMatrix(MSH2.Row, 2) & "'group by 产品名称", cnn, 1, 1
        If rs.RecordCount > 0 Then
        Do While Not rs.EOF
        Combo1.AddItem rs("产品名称")
        rs.MoveNext
        Loop
        rs.Close: Set rs = Nothing
        Call closeCn
        End If
        
        Combo1.Visible = True
        Combo1.SetFocus
    ElseIf MSH2.Col = 20 Then
    T1.Text = MSH2.TextMatrix(MSH2.Row, MSH2.Col)
    T1.Move MSH2.CellLeft, MSH2.CellTop, MSH2.CellWidth, MSH2.CellHeight
    T1.BackColor = RGB(222, 222, 222)
    T1.Visible = True
    T1.SetFocus
    End If
End If
MSH2.Refresh
Call ProcessMessages(MSH2)
End Sub


天道酬勤
2011-11-18 14:26
快速回复:access数据库查询问题
数据加载中...
 
   



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

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