my database is on the attachment. Im decent with vb programming but suck with databases! Basically Ive to accomplish the following. I created code for a calendar that allow a user to enter a value for any date in the calendar. I need to take the values they entered into my vb calendar and save the dates with a value to my database. If I were working with one table it wouldnt be a problem. Unfortunately Im using ADO which only allows for 1 table connection at a time. To compensate for this i used 2 ado connections. 1 for each table. The details table shold store the date of an infraction for the employee(infraction-Date that employee screwed their attendance up by a no-call/no-show, coming in late, etc)
My problem is if an infraction is entered it might be the first time that employee got an infraction and i get an error because im moving both tables at the same time. I know basically im supposed to use an if exists clause for this and then next time the details page is available then re synchronize the tables according to employee id. My prob is I only know what it says in a book. Ive no practical experience. I guess what is like to see is a very simple
vb program hooked up to a database with 2 table a main table and a details table. Then I would be fine As i can pick apart the code to see what it does.
Normally Id just attach my project as a whole but as thier are very complicated calculations in it, Im not yet done with my error checking for these calulations.
Also from what I do know of databases and structure I currently have my table setup correctly I wanted to verify that at this point and hopefully ...see a sample program of this as stated above.You can only have one DATABASE per ADO Connection but the connection CAN operate on multiple tables as long as they all reside in the same database.|||Here's a VERY Q&D example that uses the Northwind DB and lists the products ordered for May 1998.
'******************************
Dim ado As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim sql As String
Private Sub Form_Load()
ado.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=GRAHAMT"
ado.Open
sql = "SELECT OrderID, CustomerID FROM Orders WHERE OrderDate >= '1998/05/01' Order By OrderID"
rs1.Open sql, ado, adOpenForwardOnly, adLockReadOnly
If Not rs1.EOF Then
While Not rs1.EOF
sql = "SELECT ProductID From [Order Details] Where OrderID=" & CStr(rs1!OrderID)
rs2.Open sql, ado, adOpenForwardOnly, adLockReadOnly
If Not rs2.EOF Then
While Not rs2.EOF
Debug.Print rs1!OrderID, rs2!ProductID
rs2.MoveNext
Wend
End If
rs2.Close
rs1.MoveNext
Wend
End If
rs1.Close
ado.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set ado = Nothing
End Sub|||... and before anybody says it, I know the example is lousy coding, it's just to show that you CAN have multiple tables open through one connection. Obviously a JOIN would be more efficient in the select but I'll leave the syntax of that for one of the SQL experts.
:)
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Monday, March 19, 2012
newbie needs simple help
Monday, March 12, 2012
Newbie help On Sql string form vb
HI, I just started db programming for this project I am working on. I am having a problem joining two tables where both of their "EmployeeID" fields is equal to my Vb EmpID string...
I was trying the code:
SqlQuery = "SELECT TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID WHERE TblEmpAttendance.EmployeeID" & _
"= TblEmpAttendance.EmployeeID AND TblAttendance.EmployeeID=" & EmpID
Any help would be appreciated.
Thanks
-Greg S.Oops I already posted it but ill dbl chk anyhow. I got it to work using:
SqlQuery = "SELECT TblEmpAttendance.EmployeeID, TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID = TblEmpAttendance.EmployeeID WHERE TblEmployees.EmployeeID = " & EmpID
Is their anyhting that could cause problems with this statement?
Thanks
-Greg S
I was trying the code:
SqlQuery = "SELECT TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID WHERE TblEmpAttendance.EmployeeID" & _
"= TblEmpAttendance.EmployeeID AND TblAttendance.EmployeeID=" & EmpID
Any help would be appreciated.
Thanks
-Greg S.Oops I already posted it but ill dbl chk anyhow. I got it to work using:
SqlQuery = "SELECT TblEmpAttendance.EmployeeID, TblEmpAttendance.Date, TblEmpAttendance.Value," & _
"TblEmployees.TotalPoints, TblEmployees.DaysWorked FROM TblEmployees RIGHT JOIN TblEmpAttendance ON TblEmployees.EmployeeID = TblEmpAttendance.EmployeeID WHERE TblEmployees.EmployeeID = " & EmpID
Is their anyhting that could cause problems with this statement?
Thanks
-Greg S
Monday, February 20, 2012
Newbie
Friends,
I am a newbie in sql programming, I don't know much about the programming.
I 've tried to make a trigger but it failed.
Where can I learn about it and rather free for payments. ( Sorry about that
statement, cause it rather expensive for my revenue)
--
Message posted via http://www.sqlmonster.comTry to learn it in BOL
Madhivanan|||In case you are not aware... BOL = Books Online, which is the help that
comes with the SQL Server client utilities. You can also get a lot of
information from Microsoft's website (www.microsoft.com). If you have
specific questions, then you can of course post them here.
-Tom.
Subscribe to:
Posts (Atom)