|
-
May 18th, 2012, 02:59 AM
#7
Re: SQL Codes don't work for me.. i can't figure out what im doing wrong.
 Originally Posted by ColinE66
But anyway, TempSet3 is declared as a RecordSet. I believe that you need a Connection object to do the insert.
i.e. conn.execute not TempSet3 .execute
This is correct. Recordsets are used when you need to return data from DB (SELECT). When you're executing INSERT or UPDATE operations nothing returns so these have to be run using ConnectionObject.Execute or using a Command Object.
@Hijazzer, you said you want to remove unwanted data but it's not clear what's the criteria to know what's unwanted data, you want to keep rows on table Ogrenci when Ogrenci.OGRNO corresponds with Notlar.ogrenci and DersKodu = Ana_Sayfa.dk, or you want to remove this rows from table Ogrenci? If you want to keep this rows then try something like:
Code:
Dim conn As ADODB.Connection, rs As ADODB.Recordset, StrSql As String
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\Math.accdb;Jet OLEDB:Database Password=****you216;"
conn.Open
StrSql = "INSERT INTO TempOgrenci (Ad,Soyad,OGRNO)" & _
" SELECT A.OGRNO, A.ad, .A.Soyad " & _
" FROM Ogrenci A INNER JOIN Notlar B ON A.OGRNO = B.ogrenci " & _
" WHERE B.DersKodu = " & Ana_Sayfa.dk
conn.Execute StrSql
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select OGRNO,Ad,Soyad from TempOgrenci", conn
Set DataGrid1.DataSource = rs
rs.Close
Set rs = Nothing
Set conn = Nothing
If what you need is the opposite (excluding registers where DersKodu = Ana_Sayfa.dk) then you need to change the red = in previous code to <>
I'm assuming there is only 1 key needed to joins these tables: [Ogrenci.OGRNO] should match [Notlar.ogrenci], if there are more then they should be added to this query.
If this is not what you need then please specify what's your criteria to understand which rows should be excluded and which not.
Last edited by jcis; May 18th, 2012 at 03:06 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|