473,386 Members | 1,973 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,386 software developers and data experts.

Parameterized SQL UPDATE issues...

patjones
931 Expert 512MB
Hi all:

I've got one of those problems that I just can't get around, no matter what! In my code, I've got a SQL UPDATE like:

Expand|Select|Wrap|Line Numbers
  1.  
  2. strSaveLeave = "UPDATE tblLeave 
  3. SET fldLeaveType = @LeaveType, 
  4.         fldLeaveStatus = @LeaveStatus, 
  5.         fldDateLastWorked = @DateLastWorked, 
  6.         fldDateLeaveStart = @DateLeaveStart, 
  7.         fldDateLastPaid = @DateLastPaid, 
  8.         fldDateLeaveEnd = @DateLeaveEnd, 
  9.         fldDateWarningLetter = @DateWarningLetter, 
  10.         fldDateAWOLEmail = @DateAWOLEmail, 
  11.         fldDateReturnEmail = @DateReturnEmail, 
  12.         fldDateReturned = @DateReturned, 
  13.         fldLeaveNotes = @LeaveNotes 
  14. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN" 
My parameters are created like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. .Parameters.Append .CreateParameter("ERN", adBSTR, adParamInput, 7, currLeave.ERN)
  3. .Parameters.Append .CreateParameter("LeaveNum", adInteger, adParamInput, , currLeave.LeaveNum)
  4. .Parameters.Append .CreateParameter("LeaveType", adInteger, adParamInput, , currLeave.LeaveType)
  5.  
  6.  
...and so on. In this table, fldERN is a foreign key that connects to it's primary key counterpart in another table - however for the purpose of this UPDATE, I'm only working with this table.

Now, when I run this code, it doesn't give me any errors. It's simply that nothing happens. I open up an existing record in the form, make a few changes, hit my save button...and the changes don't show up in the record. What's interesting though is that when I construct the WHERE clause using strings and comment out the .CreateParameter lines for ERN and LeaveNum like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE tblLeave.fldERN = '" & currLeave.ERN & "' AND tblLeave.fldLeaveNum = " & currLeave.LeaveNum
  3.  
...it works fine! I just don't know why the statement won't work when I use parameters in the WHERE clause. Any insight? Thanks so much...

Pat
Jun 10 '08 #1
20 2619
Stewart Ross
2,545 Expert Mod 2GB
Hi. The parameter for the ERN field appears to be a string, but in your WHERE clause (line 13 in first code block above) you are not referring to it within quotes. It will be interpreted as if it were a number unless you put it in quotes - which you did do in the other WHERE that works fine (last code posted)!

I am not sure which back-end application you are using (with all the @s involved in the SQL), nor do I know for certain that you are using Access VBA and not VB, say, to build the string. Assuming you are building the SQL string in Access VBA or VB please try replacing your WHERE line with
Expand|Select|Wrap|Line Numbers
  1. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = '" & @ERN & "'"
The reason I am hedging a bit here is that string joins in other applications may use a different operator ("+", say, instead of the "&"). As far as I know the use of the single quote for strings is correct in the ANSI SQL standard, however.

-Stewart
Jun 10 '08 #2
patjones
931 Expert 512MB
Hi. The parameter for the ERN field appears to be a string, but in your WHERE clause (line 13 in first code block above) you are not referring to it within quotes. It will be interpreted as if it were a number unless you put it in quotes - which you did do in the other WHERE that works fine (last code posted)!

I am not sure which back-end application you are using (with all the @s involved in the SQL), nor do I know for certain that you are using Access VBA and not VB, say, to build the string. Assuming you are building the SQL string in Access VBA or VB please try replacing your WHERE line with
Expand|Select|Wrap|Line Numbers
  1. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = '" & @ERN & "'"
The reason I am hedging a bit here is that string joins in other applications may use a different operator ("+", say, instead of the "&"). As far as I know the use of the single quote for strings is correct in the ANSI SQL standard, however.

-Stewart
Hi Stewart:

Thanks for your suggestion (and yes I am using Access/VBA), but unfortunately that doesn't even compile. It responds with a syntax error.

Although I'm fairly new to the parameterization process...I was under the impression that what you are suggesting here wasn't necessary. It seems that one of the advantages to parameterization is that one doesn't have to do all the string building that is necessary when using straight text box or field names. At least, that is what I've seen in my travels around various forums regarding the issue...

Pat
Jun 10 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. Regardless of parameterisation you will still need to delimit a string within the SQL in quotes. Why? Because otherwise the string would be interpreted like this after parameter substitution (using a dummy value for illustration)

WHERE fldERN = ABCDEF12345

instead of

WHERE fldERN = 'ABCDEF12345'

and this in turn will set the SQL interpreter looking for a field named ABCDEF12345 or whatever to find its value - and it will not succeed.

The fact that it worked for you in the other WHERE clause within the single quotes but without the parameter is a sure sign of what is wrong.

As for the compile error I cannot guess at that one, but I am sure that if you can resolve this you will resolve the issue at hand.

-Stewart
Jun 10 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
Ahh, your parameter has to be part of the string it would appear, at least from the way it is built in your example - hence the compile error??. Modifying:

Expand|Select|Wrap|Line Numbers
  1. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = '@ERN'"
-Stewart
Jun 10 '08 #5
patjones
931 Expert 512MB
Ahh, your parameter has to be part of the string it would appear, at least from the way it is built in your example - hence the compile error??. Modifying:

Expand|Select|Wrap|Line Numbers
  1. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = '@ERN'"
-Stewart
That compiles fine but gives me no results, and I can understand why. Doing it this way, my WHERE clause reads:

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = 
  3. '@ERN'
  4.  
This means that my actual value in fldERN would have to be "@ERN" which doesn't make any sense.

I have done this previously using just

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = 
  3. @ERN
and all the forums I've looked in have shown it this way. So I still don't see the necessity of putting it in quotes...

Pat
Jun 10 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
OK. My experience with parameter queries has been through DAO rather than ADO recordsets. Anyway, I have trawled the (completely inadequate) documentation on the use of parameter queries with ADO. I agree with you now that you should not have to enclose the parameter in quotes. The parameters are explictly typed (rather than typeless), which is one difference.

What I am puzzled by in your code is the @ syntax; the references in the documentation to parameters indicate the use of question marks as placeholders when using the command object, and in my test code below the parameter of a field keyw is set this way. It is not an update query, just a select, but it does indeed return a recordset based on a where clause matched on the string value as expected.

I saw a reference to the @ form of parameter with the Inputparameters property, but the documentation still refers to the ? markers within the code itself. Perhaps if you posted more of your code (the bits where the parameters are passed and so on) the mystery can finally be solved?

I also found the locals window of the debugger very useful for checking the actual settings of the command object and the parameter object in testing the simple example below.

Expand|Select|Wrap|Line Numbers
  1.     Dim RS As New ADODB.Recordset
  2.     Dim cmd As New ADODB.Command
  3.     Dim param As New ADODB.Parameter
  4.     Dim conn As New ADODB.Connection
  5.     cmd.CommandText = "select * from keywords where keyw like ?"
  6.     cmd.CommandType = adCmdText
  7.     Set param = cmd.CreateParameter("keyw", adChar, adParamInput, 255, "coin")
  8.     cmd.Parameters.Append param
  9.     Set conn = CurrentProject.Connection
  10.     cmd.ActiveConnection = conn
  11.     Set RS = cmd.Execute
  12.     Do While Not RS.EOF
  13.         Debug.Print RS!Keyw
  14.         RS.MoveNext
  15.     Loop
  16.     RS.Close
  17.  
-Stewart
Jun 10 '08 #7
patjones
931 Expert 512MB
Thanks so much Stewart. From what I can see, the "@" formalism is when you use named parameters, such as I'm doing. The "?" formalism seems to be when you define a list of parameters, and then use those parameters in the query in the order you defined them in the list.

I don't know that it will help, but this is the whole subroutine I'm using for saving the data in this particular form. The booEdit that I send in is just a boolean telling the subroutine whether this is a brand new record, or an edit to an existing record. You can see that it picks out different SQL statements on the basis of what booEdit is. The first branch of the If-statement logic (the case for a new record) works just fine. It's the second branch which causes the trouble we've been discussing all day:

Expand|Select|Wrap|Line Numbers
  1.  Public Sub SaveLeave(booEdit As Boolean) 
  2.  
  3. On Error GoTo Err_SaveLeave
  4.  
  5. Dim strSaveLeave As String
  6. Dim commSaveLeave As ADODB.Command
  7.  
  8. 'Set the SQL string for updating the leave table...
  9.  
  10. If Not booEdit Then
  11.  
  12.     strSaveLeave = "INSERT INTO tblLeave (fldERN, fldLeaveNum, fldLeaveType, fldLeaveStatus, fldDateLastWorked, fldDateLeaveStart, fldDateLastPaid, fldDateLeaveEnd, fldDateWarningLetter, fldDateAWOLEmail, fldDateReturnEmail, fldDateReturned, fldLeaveNotes) VALUES (@ERN, @LeaveNum, @LeaveType, @LeaveStatus, @DateLastWorked, @DateLeaveStart, @DateLastPaid, @DateLeaveEnd, @DateWarningLetter, @DateAWOLEmail, @DateReturnEmail, @DateReturned, @LeaveNotes)"
  13.  
  14. Else
  15.  
  16.     strSaveLeave = "UPDATE tblLeave SET fldLeaveType = @LeaveType, fldLeaveStatus = @LeaveStatus, fldDateLastWorked = @DateLastWorked, fldDateLeaveStart = @DateLeaveStart, fldDateLastPaid = @DateLastPaid, fldDateLeaveEnd = @DateLeaveEnd, fldDateWarningLetter = @DateWarningLetter, fldDateAWOLEmail = @DateAWOLEmail, fldDateReturnEmail = @DateReturnEmail, fldDateReturned = @DateReturned, fldLeaveNotes = @LeaveNotes WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN"
  17.  
  18. End If
  19.  
  20. 'Set command information for leave
  21.  
  22. Set commSaveLeave = New ADODB.Command
  23.  
  24. With commSaveLeave
  25.  
  26.     .CommandType = adCmdText
  27.     .CommandText = strSaveLeave
  28.     .ActiveConnection = conn.ConnectionString
  29.  
  30.     .Parameters.Append .CreateParameter("ERN", adVarChar, adParamInput, 7, currLeave.ERN)
  31.     .Parameters.Append .CreateParameter("LeaveNum", adInteger, adParamInput, , currLeave.LeaveNum)
  32.     .Parameters.Append .CreateParameter("LeaveType", adInteger, adParamInput, , currLeave.LeaveType)
  33.     .Parameters.Append .CreateParameter("LeaveStatus", adBSTR, adParamInput, 1, currLeave.LeaveStatus)
  34.     .Parameters.Append .CreateParameter("DateLastWorked", adVarChar, adParamInput, 8, currLeave.DateLastWorked)
  35.     .Parameters.Append .CreateParameter("DateLeaveStart", adVarChar, adParamInput, 8, currLeave.DateLeaveStart)
  36.     .Parameters.Append .CreateParameter("DateLastPaid", adVarChar, adParamInput, 8, currLeave.DateLastPaid)
  37.     .Parameters.Append .CreateParameter("DateLeaveEnd", adVarChar, adParamInput, 8, currLeave.DateLeaveEnd)
  38.     .Parameters.Append .CreateParameter("DateWarningLetter", adVarChar, adParamInput, 8, currLeave.DateWarningLetter)
  39.     .Parameters.Append .CreateParameter("DateAWOLEmail", adVarChar, adParamInput, 8, currLeave.DateAWOLEmail)
  40.     .Parameters.Append .CreateParameter("DateReturnEmail", adVarChar, adParamInput, 8, currLeave.DateReturnEmail)
  41.     .Parameters.Append .CreateParameter("DateReturned", adVarChar, adParamInput, 8, currLeave.DateReturned)
  42.     .Parameters.Append .CreateParameter("LeaveNotes", adVarChar, adParamInput, 250, currLeave.LeaveNotes)
  43.  
  44. End With
  45.  
  46. commSaveLeave.Execute
  47.  
  48. Exit_SaveLeave:
  49.     Exit Sub
  50.  
  51. Err_SaveLeave:
  52.     HandleSystemError Err.Number, , "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & "Subroutine: SaveLeave. Module: basGlobals."
  53.     Resume Exit_SaveLeave
  54.  
  55. End Sub
  56.  
Is it possible that this problem could be arising due to the fact that many of the fields I'm trying to update (fldERN, fldLeaveType, fldLeaveStatus) are connected to other tables via INNER JOIN relationships in Access? I'm so at a loss.

Pat
Jun 10 '08 #8
Stewart Ross
2,545 Expert Mod 2GB
Hi Pat. I sure see how frustrating this one is for you. As the first branch of the IF, the INSERT, works correctly the use of the parameters is correct and relationships will not be impeding anything - the table is clearly updatable or the first part would not work.

Problem is that without being able to see what the final result of the code is (because the parameters are substituted within the execute statement) it is hard to debug.

What may help is to copy your code into another procedure, and adjust it for debug purposes by replacing the UPDATE with a SELECT statement you can use to debug, like the example below:

Expand|Select|Wrap|Line Numbers
  1. Dim RS as New ADODB.Recordset
  2. ...
  3. strSaveLeave = "SELECT * from tblLeave WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN"
  4. ...
  5. set RS = commSaveLeave.Execute
  6. Do while not RS.Eof
  7. Debug.Print RS!fldERN, RS!fldLeaveNum
  8. Rs.Movenext
  9. loop
  10. RS.close
If you have an empty recordset you know that the WHERE is not matching any records. if you wanted to test what the parameters were you could set a breakpoint at the command execute and look at the parameters to check what is set.

You could even include them in the SELECT for debug purposes:

Expand|Select|Wrap|Line Numbers
  1. strSaveLeave = "SELECT @LeaveNum as prmLeaveNum, @ERN as prmERN from tblLeave"
Good luck with your checking. If I come up with anything else in the meantime I'll post back here to let you know.

-Stewart
Jun 10 '08 #9
patjones
931 Expert 512MB
Hi Pat. I sure see how frustrating this one is for you. As the first branch of the IF, the INSERT, works correctly the use of the parameters is correct and relationships will not be impeding anything - the table is clearly updatable or the first part would not work.

Problem is that without being able to see what the final result of the code is (because the parameters are substituted within the execute statement) it is hard to debug.

What may help is to copy your code into another procedure, and adjust it for debug purposes by replacing the UPDATE with a SELECT statement you can use to debug, like the example below:

Expand|Select|Wrap|Line Numbers
  1. Dim RS as New ADODB.Recordset
  2. ...
  3. strSaveLeave = "SELECT * from tblLeave WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN"
  4. ...
  5. set RS = commSaveLeave.Execute
  6. Do while not RS.Eof
  7. Debug.Print RS!fldERN, RS!fldLeaveNum
  8. Rs.Movenext
  9. loop
  10. RS.close
If you have an empty recordset you know that the WHERE is not matching any records. if you wanted to test what the parameters were you could set a breakpoint at the command execute and look at the parameters to check what is set.

You could even include them in the SELECT for debug purposes:

Expand|Select|Wrap|Line Numbers
  1. strSaveLeave = "SELECT @LeaveNum as prmLeaveNum, @ERN as prmERN from tblLeave"
Good luck with your checking. If I come up with anything else in the meantime I'll post back here to let you know.

-Stewart
Hi:

I will try building a SELECT query and see if it picks out the correct records. In the meantime, what I can say is that I did do this:

Expand|Select|Wrap|Line Numbers
  1. For j = 0 to commSaveLeave.Parameters.Count-1
  2.      Debug.Print commSaveLeave.Parameters.Item(j)
  3. Next
When I opened my Immediate Window to see the results of this, I found that the parameters were all assigned correctly.

You are quite correct that, what makes this frustrating, is that the INSERT statement works well. The UPDATE statement is nearly identical except for the WHERE clause, so I have to suspect that the issue lies there. Again, I'm going to try out the SELECT query you suggested.

Thanks for all your help...

Pat
Jun 11 '08 #10
Delerna
1,134 Expert 1GB
Been perusing the posts here and I agree that it dosn't make sense that the insert works but the update dosn't.
Since Nothing happens for the update, I'm going to suggest something silly that I've been caught on before.

The update has a where condition and one of the parameters is a varchar.

WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN

So the problem would't be something like fldERN being a Char(10) type would it?
Where "Happy " = "Happy" will not match.

I usually trim the field if thats the case
WHERE tblLeave.fldLeaveNum = @LeaveNum AND trim(tblLeave.fldERN) = @ERN

Just suggesting....I hope it helps!
Jun 11 '08 #11
patjones
931 Expert 512MB
Been perusing the posts here and I agree that it dosn't make sense that the insert works but the update dosn't.
Since Nothing happens for the update, I'm going to suggest something silly that I've been caught on before.

The update has a where condition and one of the parameters is a varchar.

WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN

So the problem would't be something like fldERN being a Char(10) type would it?
Where "Happy " = "Happy" will not match.

I usually trim the field if thats the case
WHERE tblLeave.fldLeaveNum = @LeaveNum AND trim(tblLeave.fldERN) = @ERN

Just suggesting....I hope it helps!
Hi Delerna:

You are talking about something which I've wondered about, which is, how sensitive is this whole process to the type that is set in the .CreateParameter statement? I have pretty much used adVarChar for everything, including currLeave.ERN. But the fact is, the ERN is always a seven digit text string (not a number, because it often begins with one or more zeroes). That's why I set the parameter size = 7 for the ERN parameter.

The table (i.e. fldERN) is, I believe, designed in accordance with that understanding, but I have to go back and check that to be sure. It's been a while since I put the back end together!

Thanks for the suggestion, and I'll let you know how it works out!

Pat
Jun 11 '08 #12
Delerna
1,134 Expert 1GB
Yep, the difference between varchar and char is significant in where clauses. As I said, it has caught me out before. The difference between int and bigint isn't so critical so long as the numbers at the time aren't bigger than int.
ie 64 as an int is the same as 64 as a bigint. Other types i'm not sure about.
Jun 11 '08 #13
patjones
931 Expert 512MB
Hi Pat. I sure see how frustrating this one is for you. As the first branch of the IF, the INSERT, works correctly the use of the parameters is correct and relationships will not be impeding anything - the table is clearly updatable or the first part would not work.

Problem is that without being able to see what the final result of the code is (because the parameters are substituted within the execute statement) it is hard to debug.

What may help is to copy your code into another procedure, and adjust it for debug purposes by replacing the UPDATE with a SELECT statement you can use to debug, like the example below:

Expand|Select|Wrap|Line Numbers
  1. Dim RS as New ADODB.Recordset
  2. ...
  3. strSaveLeave = "SELECT * from tblLeave WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN"
  4. ...
  5. set RS = commSaveLeave.Execute
  6. Do while not RS.Eof
  7. Debug.Print RS!fldERN, RS!fldLeaveNum
  8. Rs.Movenext
  9. loop
  10. RS.close
If you have an empty recordset you know that the WHERE is not matching any records. if you wanted to test what the parameters were you could set a breakpoint at the command execute and look at the parameters to check what is set.

You could even include them in the SELECT for debug purposes:

Expand|Select|Wrap|Line Numbers
  1. strSaveLeave = "SELECT @LeaveNum as prmLeaveNum, @ERN as prmERN from tblLeave"
Good luck with your checking. If I come up with anything else in the meantime I'll post back here to let you know.

-Stewart
Good Morning:

I tried replacing my UPDATE with a SELECT, as you suggested Stewart, and it functions perfectly fine with that WHERE clause! What is it about this UPDATE statement? Yikes.

Pat
Jun 11 '08 #14
patjones
931 Expert 512MB
Been perusing the posts here and I agree that it dosn't make sense that the insert works but the update dosn't.
Since Nothing happens for the update, I'm going to suggest something silly that I've been caught on before.

The update has a where condition and one of the parameters is a varchar.

WHERE tblLeave.fldLeaveNum = @LeaveNum AND tblLeave.fldERN = @ERN

So the problem would't be something like fldERN being a Char(10) type would it?
Where "Happy " = "Happy" will not match.

I usually trim the field if thats the case
WHERE tblLeave.fldLeaveNum = @LeaveNum AND trim(tblLeave.fldERN) = @ERN

Just suggesting....I hope it helps!
Hi Delerna:

I tried replacing adVarChar with adChar, but the result is the same. I'm going to keep it at adChar anyway, because I believe that's exactly what it should be. What about my LeaveNum parameter? That is always going to be an integer that never exceeds 4 or 5. Is adInteger proper for that? It's sort of a moot point, because I discovered already that the WHERE clause functions fine in the context of a SELECT statement (see my above post), but I would like to know anyway. Thanks!

Pat
Jun 11 '08 #15
Stewart Ross
2,545 Expert Mod 2GB
Hi Pat. Curioser and curioser... The Select working tells us that the Where does not appear to be the problem at all. To me, it suggests that the Update is not in fact updatable - because of an error occurring at time of interpretation perhaps.

In your code all your date parameters are defined as VarChar strings and not dates - is this correct? I ask because although Access is very good at converting types on the fly, it could be possible that the string values are not matching the format expected for dates in SQL and causing errors. A bit of a long-shot, but one to consider.

-Stewart
Jun 11 '08 #16
patjones
931 Expert 512MB
Hi Pat. Curioser and curioser... The Select working tells us that the Where does not appear to be the problem at all. To me, it suggests that the Update is not in fact updatable - because of an error occurring at time of interpretation perhaps.

In your code all your date parameters are defined as VarChar strings and not dates - is this correct? I ask because although Access is very good at converting types on the fly, it could be possible that the string values are not matching the format expected for dates in SQL and causing errors. A bit of a long-shot, but one to consider.

-Stewart
It's a good point, but assuming that's the case why would the INSERT work? This is a real tough one. I've even gone so far as to paste the UPDATE string into Word and print it out in 16-point type size hoping that something will jump out at me!

Pat
Jun 11 '08 #17
Delerna
1,134 Expert 1GB
Select instead of update works!
Insert works!
I think that we may have proved that the problem is not in the code. Its time to look elsewhere.


More suggestions. You may have checked these already?
When you create the connection object you supply a user and password.
1) Is the user you are using permitted to make updates in the tables permissions?
2) Is the tables key fields defined sufficiently to uniquely identify records. SQL server and ADO can be a bit iffy wth updates as well as deletes if records cannot be uniquely defined.
3) One more for the code. Have all the settings required for successful updates with ADO objects to occur been set correctly? I don't keep them in my head (getting too old.....grin), I usually search my own notes or google.
For example with the recordset object (not what you are using but illustrates the point),the default cursor type is forward only. I dont think that cursor type supports updating a record.
Jun 11 '08 #18
patjones
931 Expert 512MB
Select instead of update works!
Insert works!
I think that we may have proved that the problem is not in the code. Its time to look elsewhere.


More suggestions. You may have checked these already?
When you create the connection object you supply a user and password.
1) Is the user you are using permitted to make updates in the tables permissions?
2) Is the tables key fields defined sufficiently to uniquely identify records. SQL server and ADO can be a bit iffy wth updates as well as deletes if records cannot be uniquely defined.
3) One more for the code. Have all the settings required for successful updates with ADO objects to occur been set correctly? I don't keep them in my head (getting too old.....grin), I usually search my own notes or google.
For example with the recordset object (not what you are using but illustrates the point),the default cursor type is forward only. I dont think that cursor type supports updating a record.
Good Morning Delerna:

I'm starting to feel as though the problem is elsewhere also. In regard to your suggestions:

1) There really aren't any permissions set right now. It's completely open access.

2) This is something I've considered, and it still may be a problem. "tblLeave" is connected via one-to-many relationships to three other tables; in particular fldERN, fldLeaveType and fldLeaveStatus are all primary keys in other tables, and act as foreign keys in tblLeave. Now, I realize that if I try to update one of these fields to a value that doesn't exist in the corresponding primary key field in one of the other tables, the UPDATE wouldn't work; but I would also expect Access to throw an error in that instance.

3) I'm aware of the CursorType issue, but like you say - I'm not using a recordset here. I'm simply executing the ADO command, then clearing it and leaving the subroutine.

These are all pertinent ideas, but I keep coming back to this...if for instance this was a key issue, as in point #2, why would this work:

Expand|Select|Wrap|Line Numbers
  1. strSaveLeave = "UPDATE tblLeave SET fldLeaveType = @LeaveType, fldLeaveStatus = @LeaveStatus, fldDateLastWorked = @DateLastWorked, fldDateLeaveStart = @DateLeaveStart, fldDateLastPaid = @DateLastPaid, fldDateLeaveEnd = @DateLeaveEnd, fldDateWarningLetter = @DateWarningLetter, fldDateAWOLEmail = @DateAWOLEmail, fldDateReturnEmail = @DateReturnEmail, fldDateReturned = @DateReturned, fldLeaveNotes = @LeaveNotes WHERE fldLeaveNum = " & currLeave.LeaveNum & " AND fldERN = '" & currLeave.ERN & "'"
  2.  
Because, as I determined earlier, it functions fine with there WHERE clause written out as a string. Very strange, no?

Pat
Jun 12 '08 #19
patjones
931 Expert 512MB
Hi:

It seems that I have found a way around the problem, rather than solving it. I tried:

Expand|Select|Wrap|Line Numbers
  1.  
  2. UPDATE tblLeave SET fldLeaveType = ?, fldLeaveStatus = ?, fldDateLastWorked = ?, fldDateLeaveStart = ?, fldDateLastPaid = ?, fldDateLeaveEnd = ?, fldDateWarningLetter = ?, fldDateAWOLEmail = ?, fldDateReturnEmail = ?, fldDateReturned = ?, fldLeaveNotes = ? WHERE tblLeave.fldLeaveNum = ? AND tblLeave.fldERN = ?
  3.  
By putting the .CreateParameter statements in the same order that I need to use the respective parameters in the UPDATE, it worked fine. I'm still not sure why using the named parameters didn't work. However, the "?" formalism seems to be functioning so far.

Thanks for everyone's input.

Pat
Jun 12 '08 #20
Delerna
1,134 Expert 1GB
Cool you got it working. The solution was expressed in an earlier post by stewart.

Another way around the problem would have been to use a parameterised stored procedure on sql server and let the stored proc decide whether to insert or update via an if exists framework.

All your vb code would then need to do would be to build a query string and have the connection execute it. The string would have the form.

strSQL="exec NameOfStoredProc value1,value2,value3......."

This simplifies your vb code, removes all those horrible add parameter lines and lets more of the work be done at the server rather than back and forth between the client and the server.
Jun 13 '08 #21

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
7
by: Wayne Wood | last post by:
i posted this problem on microsoft.public.excel.programming, but there's no one replied till now. because this issue is time critical, i put it here to try my fortune :) ...
4
by: Gilberto Campos | last post by:
Hi all. I am having a strange problem. I am developping an application that acceses an Access db through Jet (.UDL files). I have writen parametric INSERT queries that work fine. I am now...
4
by: Steve Franks | last post by:
I'm new to ASP.NET and working with the 2.0 beta. As a classic ASP developer I have a lot of code that looks like this: sql = "insert into x values(" sql = sql & val1 & ", " & val2 & ", ' " &...
1
by: Peter | last post by:
Hi, When I update/add a new web reference to a web service class with a parameterized constructor, what is preventing the generated proxy from including a definition for the parameterized...
0
by: Tom | last post by:
Looking for some help with stored procedure call issues. Conceptually, I need to pass a data structure as the sole parameter to the Oracle stored procedure. Sounds simple enough....but how? ...
0
by: BenCoo | last post by:
Hello colleagues, I have a ObjectDataSource wich is linked to a SQL Server 2005 database I a gridview I have data and on each row a "Edit button" wich wil show the selected record in editmode....
4
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
For MS SQL Server... I am used to declaring local variables in my SQL queries... Declare @MyInt int, @MyChar varchar(33) Parameters were idenfitied with a colon... Where ModDate :MyDate But,...
2
by: bob | last post by:
Hi, Its been a long time since I have had the joy of feeding parameterized query CommandText strings to an OleDBCommand object. I have tried all manner of versions of " update foo set bar = @bar...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.