3 Replies - 4314 Views - Last Post: 21 December 2012 - 03:03 AM Rate Topic: -----

#1 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

VB6 - SQL query error

Posted 20 December 2012 - 07:22 AM

Hi. I am using vb6 for searching and displaying a particular record from MS-ACCESS.
I have two forms namely Search1 and Search2.
In the Search1 form, I have two combobox named degree and branch1 and one button named search.
I have retrieved the data for those two combobox from two different tables named "degree" and "dept" from MS-ACCESS database.
But the data i am going to search from another table named "subjectcode".
When I click search button, the corresponding full record of select item in two comobobox should be displayed in the Datagrid named "Grid1" that placed in the Search2.
Here is my complete code and i am getting error while I use sql query to retrieve and display those data.
Here is the code of Search1 of Form_Load

Private Sub Form_Load()
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\college.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
    If con.State = 0 Then
        MsgBox "Connection Failed! Check Connection", "Error"
    End If
    
    Set rs = New ADODB.Recordset
    rs.Open "select distinct DegId from Degree", con, 1, 3
        Do Until rs.EOF
            degree.AddItem rs.Fields(0)
            rs.MoveNext
        Loop
        rs.Close
    rs.Open "select distinct DeptName from Dept", con, 1, 3
        Do Until rs.EOF
            branch1.AddItem rs.Fields(0)
            rs.MoveNext
        Loop
        rs.Close
End Sub

Private Sub search_Click()
      Set rs = New ADODB.Recordset
      rs.Open "select * from subjectcode where degree='" & degree, "Branch=" & branch1, con, 1, 3
      Set Search2.Grid1.DataSource = rs
      Search2.Show
      Search1.Hide
End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: VB6 - SQL query error

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: VB6 - SQL query error

Posted 21 December 2012 - 02:24 AM

 rs.Open "select * from subjectcode where degree='" & degree & "'  And Branch='" & branch1 &"'", con, 1, 3


some thing missing in your query statement i changed it
and also what kind of grid it is, datagrid,dbgrid adn so on..

This post has been edited by thava: 21 December 2012 - 02:26 AM

Was This Post Helpful? 1
  • +
  • -

#3 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

Re: VB6 - SQL query error

Posted 21 December 2012 - 03:01 AM

Thanks friend ! it's working ! but i have one doubt ! Consider that a form is having more than two combobox, let's say a form is having 5 combobox...
If a person not selected any of those, then all fields in the table should be displayed and at the same time, if a person selects one combobox, then the corresponding field should be displayed !
And if a person selects more than one combobox, then the two combobox values should be displayed !
IMP NOTE: I have placed all that five fields in ACCESS as "PRIMARY KEY" so the five should match !
I am using ADO Datagrid friend ! Can you get me?
Was This Post Helpful? 0
  • +
  • -

#4 anandrosan1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 20-December 12

Re: VB6 - SQL query error

Posted 21 December 2012 - 03:02 AM

Thanks friend ! it's working ! but i have one doubt ! Consider that a form is having more than two combobox, let's say a form is having 5 combobox...
If a person not selected any of those, then all fields in the table should be displayed and at the same time, if a person selects one combobox, then the corresponding field should be displayed !
And if a person selects more than one combobox, then the two combobox values should be displayed !
IMP NOTE: I have placed all that five fields in ACCESS as "PRIMARY KEY" so the five should match !
I am using ADO Datagrid friend ! Can you get me?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1