Reputation: 225
Iam trying to update records in sql through Excel . I have written down some code on a button in excel to insert and update records in sql server. I managed to insert records but getting error on update query . i have checked for solution on stackoverflow already but still getting error. Can anybody check what iam doing wrong in the following lines of code
conn.Execute = "UPDATE dbo.EmployeeInfo" _
& "SET Week= ('" & Week& "') " _
& "Time= ('" & Time & "') " _
& "DateFrom = ('" & DateFrom & "') " _
& "DatoTo = ('" & DatoTo & "') " _
& "Name= ('" & Name & "') " _
& "Description= ('" & Description & "') " _
& "Codes= ('" & Codes& "')" _
& "WHERE Week= (" & .Cells(iLoop, 1) & ")
AND DateFrom = (" & .Cells(iLoop, 3) & ")
AND DatoTo = (" & .Cells(iLoop, 4) & ")
AND Name= (" & .Cells(9, oLoop) & ")"
Upvotes: 0
Views: 207
Reputation: 496
You need a comma between each column...
conn.Execute = "UPDATE dbo.EmployeeInfo" _
& "SET Week= ('" & Week& "'), " _
& "Time= ('" & Time & "'), " _
& "DateFrom = ('" & DateFrom & "'), " _
& "DatoTo = ('" & DatoTo & "'), " _
& "Name= ('" & Name & "'), " _
& "Description= ('" & Description & "'), " _
& "Codes= ('" & Codes& "')" _
& "WHERE Week= (" & .Cells(iLoop, 1) & ")
AND DateFrom = (" & .Cells(iLoop, 3) & ")
AND DatoTo = (" & .Cells(iLoop, 4) & ")
AND Name= (" & .Cells(9, oLoop) & ")"
Upvotes: 1