|
-
Feb 17th, 2004, 05:01 AM
#1
Thread Starter
Fanatic Member
data not updated though everything wnet smooth
Code:
Private Sub cmdUpdate_Click()
Dim objConn1 As New ADODB.Connection
Set objCmd = New ADODB.Command
objConn1.Open "DSN=PRsystem"
Set objCmd.ActiveConnection = objConn1
objCmd.CommandText = " UPDATE DataBase_T SET Description = ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
" WHERE Description = ' " & describe & " ' And Qty = ' " & qty1 & " ' And Unit_Cost = ' " & uc & " ' And PR_NO = ' " & Label15.Caption & " ' "
objCmd.CommandType = adCmdText
objCmd.Execute
MsgBox " Data is updated."
If Not objConn1 Is Nothing Then
If objConn1.State Then
objConn1.Close
End If
Set objConn1 = Nothing
End If
the above seems to have no error...cuz the msgbox would appear ...however i check the databse..and it was not updated!!!?why?
-
Feb 18th, 2004, 09:14 AM
#2
PowerPoster
I would imagine you would get the msgbox if the data updated correctly, not incorrectly. Anyway, how about htis:
objConn1.Execute (" UPDATE DataBase_T SET Description = ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
" WHERE Description = ' " & describe & " ' And Qty = ' " & qty1 & " ' And Unit_Cost = ' " & uc & " ' And PR_NO = ' " & Label15.Caption & " ' ")
-
Feb 18th, 2004, 11:15 AM
#3
I would suspect your Where clause is incorrect. It does not find the record you are trying to update, which is not an error condition.
Add this to your code
VB Code:
Private Sub cmdUpdate_Click()
Dim objConn1 As New ADODB.Connection
Dim lngRowsAffected as Long
Set objCmd = New ADODB.Command
objConn1.Open "DSN=PRsystem"
Set objCmd.ActiveConnection = objConn1
objCmd.CommandText = " UPDATE DataBase_T SET Description = ' " & txtD1.Text & " ' , Qty = ' " & txtQ1.Text & " ' , Unit_Cost = ' " & txtUC1.Text & " ' " & _
" WHERE Description = ' " & describe & " ' And Qty = ' " & qty1 & " ' And Unit_Cost = ' " & uc & " ' And PR_NO = ' " & Label15.Caption & " ' "
objCmd.CommandType = adCmdText
objCmd.Execute lngRowsAfffected
If lngRowsAffected > 0 Then
MsgBox "Updated " & lngRowsAffected & " Records."
Else
MsgBox "Record does not exist with the specified criteria."
End if
If Not objConn1 Is Nothing Then
If objConn1.State Then
objConn1.Close
End If
Set objConn1 = Nothing
End If
It looks like the problem with the Where clause is that you have to many spaces.
Code:
'this portion
Qty = ' " & qty1 & " '
'should b
Qty = '" & qty1 & "'
The other criterias have the same problem. Is the datatype of the QTY field Character or Numeric? If Numeric then remove the single quotes.
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
|