Sunday, February 19, 2012

Accessing Table From Visual Basic

I have a SQL table and I want to access it using the Visual Basic Code

but first I want to check whether the row is exist to update it or not exist so I can add new row. I have wrote this code but it doesn't work.

Set mydb2 = ceg.OpenResultset("select * from ProjCost where Mon='" _
& Format(SD, "dd/MM/yyyy") & "'", rdOpenDynamic, 3)
If mydb2.EOF Then
mydb2.AddNew
mydb2(0) = Trim(ProjNum)
mydb2(1) = Trim(ProjName)
mydb2(2) = Format(SD, "MM/dd/yyyy")
mydb2(3 + (mydb1(0) - 1) * 2) = Trim(Total)
mydb2.Update
Else
mydb2.Edit
mydb2(3 + (mydb1(0) - 1) * 2) = Trim(Total)
mydb2.Update
End If

can any body tell me what is wrong with this code as it's every time add a new record instead of updating the exisitng one

Thnx

Look at your query in Profler (or just output it into any debug window) and try to run it from QA, for examlpe.
P.S. Hint: datetime field may contain time as well, Then your query will return only rows with midnight time.

No comments:

Post a Comment