473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL Statement

72
Hello der people,, i just want to ask question. Is there a sql statement that uses compare... ei. Select * from [table name] where [field name] compare???

that can be implemented with visual basic 6 using adodb???


Thank you.
May 30 '07 #1
9 1609
Killer42
8,435 Expert 8TB
As far as I know, if SQL can do it, you should be able to send it to the SQL database from VB.
May 30 '07 #2
debasisdas
8,127 Expert 4TB
Can u please specify what do u want to compare using SQL.
May 30 '07 #3
Dököll
2,364 Expert 2GB
Hello der people,, i just want to ask question. Is there a sql statement that uses compare... ei. Select * from [table name] where [field name] compare???

that can be implemented with visual basic 6 using adodb???


Thank you.
Just an idea darrel, things may have gotten sophisticate and I missed it, but I think VB may not know what access has, thus, comparing data from it against VB textboxes may no be that simple. Again, I have not researched this, someone has probably mastered it.

Long ago, I worked on a project for class and the need was to compare data in an Access database against my GUI. After banging my head for a while, and for the reason Access does/did not normally send over certain errors to VB when data not added, that sort of thing, I decided to simply write additional code to load the same data to an text file; mind you a .txt file can be compared with VB textboxes locally.

In turn, when the same data were being loaded to both the text file and my Access database at the same time, using one button, VB said no way: MsgBox "Duplicate entry, please try again", at the end of the code. Therefore, VB knew to disregard sending data anywhere, Unload Me, etc...

You may not have time to write additional code, but if you came up against a wall, I say go for it...

Hope this helps!
May 31 '07 #4
darrel
72
what i'am trying to comapre is, my database records made in access... it like this i have a table named RECORDS and has filed name "TimesStart", "TimeEnd", "ROOM", "DAYS", by the way i'am doing a scheduling system.

Now i have a GUI in vb6 thats consists of 4 combo boxes.
Combo1 is for the TimeStart
Combo2 is for the TimeEnd
Combo3 is for the ROOM
Combo4 is for the DAYS

Now, i have seperate table for TimeStart, TimeEnd, ROOM & DAYS. where they contain all the neccessary information. and its link to my GUI in vb

i uses this code to populate the datas in the tables of TimeStart, TimeEnd, ROOM and DAYS.by the all my combo boxes are in an array. and it works fine.

Expand|Select|Wrap|Line Numbers
  1. Combo1(x).additem  rs.fields("TimeStart").value
  2. Combo2(x).additem  rs.fields("TimeEnd").value
  3. Combo3(x).additem  rs.fields("ROOM").value
  4. Combo4(x).additem  rs.fields("DAYS").value
  5.  
Now what my system must do is to save, verify (if theres going to be a duplication), edit, and print.

I'am finished coding the saving part and its working now, i can save records in my database.

heres my code for it:

Expand|Select|Wrap|Line Numbers
  1. Dim rsShowRec As New ADODB.Recordset
  2. Dim cnn As New ADODB.Connection
  3.  
  4. Set cnn = New ADODB.Connection
  5. cnn.ConnectionString = _
  6.  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  7.           "Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
  8. cnn.Open
  9.  
  10. For x = 0 To 15
  11. On Error Resume Next
  12. rsShowRec.Source = "Select * from RECORDS where [SUBJECT CODES] = ' " & txtCode(x).Text & " ' "
  13. rsShowRec.Open , cnn, adOpenStatic, adLockOptimistic
  14.  
  15.     If Combo1(x).Text = "Select" Or Combo2(x).Text = "Select" Or Combo3(x).Text = "Select" Or Combo4(x).Text = "Select" Then
  16.         MsgBox ("Cannot Save blank entries"), vbCritical
  17.         rsShowRec.Close
  18.         cnn.Close
  19.         Exit Sub
  20.     Else
  21.  
  22.     If rsShowRec.RecordCount > 0 Then
  23.         Else
  24.             rsShowRec.AddNew
  25.                 rsShowRec.Fields("SUBJECT CODES") = txtCode(x).Text
  26.                 rsShowRec.Fields("TimeStart") = Combo1(x).Text
  27.                 rsShowRec.Fields("TimeEnd") = (Combo2(x).Text)
  28.                 rsShowRec.Fields("ROOM") = Combo3(x).Text
  29.                 rsShowRec.Fields("DAYS") = Combo4(x).Text
  30.             rsShowRec.Update
  31.             rsShowRec.Requery
  32.             Set rsShowRec = Nothing
  33.     End If
  34.     End If
  35.     Next
  36.  
  37.     MsgBox ("Schedule has been save!!!")
  38. End Sub
  39.  
Now am into verification method, the coding part (the one am having trouble) the purpose of these verification method is to prevent duplication of schedule before saving its just like a test if there going to be a conflict.

and here my code for that method:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdVerify_Click()
  2. Dim rs As New ADODB.Recordset
  3. Dim cnn As New ADODB.Connection
  4. Dim x As Integer
  5. Dim strSQL As String
  6.  
  7. Set cnn = New ADODB.Connection
  8. cnn.ConnectionString = _
  9.  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  10.           "Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
  11. cnn.Open
  12.  
  13. For x = 0 To 15
  14. On Error Resume Next
  15.     rs.Source = "Select * from RECORDS where [TimeStart] = '" & Combo1(x).Text & "' and [TimeEnd] = '" & Combo2(x).Text & "' and [ROOM] = '" & Combo3(x).Text & "' and [DAYS] = '" & Combo1(x).Text & "'"
  16.     rs.Open , cnn, adOpenKeyset, adLockOptimistic
  17.  
  18. If rs.RecordCount > 0 Then
  19.     MsgBox ("Conflict on the previous schedule"), vbCritical
  20.     Exit Sub
  21. Else
  22.  
  23.     MsgBox ("You can now save the schedule"), vbOKOnly
  24.     cmdSave.Enabled = True
  25. End If
  26.  
  27. Next
  28.  
  29. End Sub
  30.  
Now the scenario is like i have save a few records in the table RECORDS, with different value in TimeStart, TimeEnd, ROOM and DAYS. now i'am testing my verification method code but it seems its not working fine, because when created a schedule that has equal value store in my table RECORDS it must prompt me with an error "Conflict on the previous schedule" and if not it must prompt me "You can now save the schedule" and can save it... now the problem is eventhough ive inputted equal value in my GUI and try to verify if there an equal value in my database RECORDS table, my system prompt me that I CAN NOW SAVE THE SCHEDULE, evenethough it has an equal value in my database RECORDS. that i what am trying to figure out on how i can be able to compare the schedule that the user will be inputting from the schedule that are in my database already when they click my VERIFY button..

I hope you guys understand what i'am trying to say and do!!! i hope you can help me guys... by the its a proposed project in my work.. i'am working in a university that is not so automated in terms of there scheduling system, they are using manual system, thats why am trying to do an alternative to minimize the work and to avoid conflicts...

Thank you very much.
May 31 '07 #5
darrel
72
Guys good news i have figure out the answer to my problem, i can now compare records in my database... To contribute here's my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdVerify_Click()
  2. Dim rs As New ADODB.Recordset
  3. Dim cnn As New ADODB.Connection
  4. Dim x As Integer
  5. Dim strSQL As String
  6.  
  7. Set cnn = New ADODB.Connection
  8. cnn.ConnectionString = _
  9.  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  10.           "Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
  11. cnn.Open
  12.  
  13. For x = 0 To 15
  14. On Error Resume Next
  15.     rs.Source = "Select * from RECORDS where [TimeStart] = '" & Combo1(x).Text & "' and [TimeEnd] = '" & Combo4(x).Text & "' and [ROOM] = '" & Combo2(x).Text & "' and [DAYS] = '" & Combo3(x).Text & "'"
  16.     rs.Open , cnn, adOpenKeyset, adLockOptimistic
  17.  
  18. If rs.RecordCount > 0 Then
  19.     MsgBox ("There's a conflict in the schedule"), vbCritical
  20.     rs.Close
  21.     Exit Sub
  22.  
  23. Else
  24.  
  25.     MsgBox ("You can now save the schedule"), vbOKOnly
  26.     cmdSave.Enabled = True
  27.     Exit For
  28. End If
  29.  
  30. Next
  31.  
  32. End Sub
  33.  
Now i still have a few problems now what i want to do is after i prompt the user that theres a duplication of records with the schedule they are making, after that pop-up msg what i want to do is to highlight the schedule in my form to indicate that there's an conflict in that particular schedule,

Thank you very much for all those idea, and it helps me a lot!!! thank you very much!!! this forum rocks and helpful, i hope you continue supporting all newbies like me... hail to you all.
May 31 '07 #6
Killer42
8,435 Expert 8TB
...I think VB may not know what access has, thus, comparing data from it against VB textboxes may no be that simple.
...
additional code to load the same data to an text file; mind you a .txt file can be compared with VB textboxes locally.
I think you're trying to send darrel on a wild goose chase there, Dököll. If you can't trust your database system to faithfully record and return your data, then you might as well give up. That's exactly what the database is for, and you certainly don't need to store a redundant copy in a text file (though a backup of some sort is highly recommended, of course).

If a comparison between textboxes and database fields isn't working, it doesn't mean you can't compare the two. It just means the code is wrong.
May 31 '07 #7
Dököll
2,364 Expert 2GB
Guys good news i have figure out the answer to my problem, i can now compare records in my database...
Splendid darrel, good of you to remain persistant, furthermore, extremely nice of you to post your finding for all to see...

Good luck with this schedule!
Jun 1 '07 #8
Dököll
2,364 Expert 2GB
I think you're trying to send darrel on a wild goose chase there, Dököll. If you can't trust your database system to faithfully record and return your data, then you might as well give up. That's exactly what the database is for, and you certainly don't need to store a redundant copy in a text file (though a backup of some sort is highly recommended, of course).

If a comparison between textboxes and database fields isn't working, it doesn't mean you can't compare the two. It just means the code is wrong.
Bit of confusion in relaying the info, my database responded quite well, I searched, added, deleted, updated to it (Searching for data before submitting was my next option to darrel). What happened, and this is because I worked on this a very long time ago, is I could not quite pin down a compare method. So I went to work. Since I am familiar with text files, was able to found a solution; data was therefore neither recorded to the Text file nor the Access database...Nevetheless, I am rather glad our dear darrel did not have to do this as I cautioned it as a last step:-)
Jun 1 '07 #9
darrel
72
No problem with my friends! this forum helps me a lot by reading some old & new thread to get some ideas...

Hoping that youll continue guys with my future problem in my time scheduling system.
Jun 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.