2

I have a bit of a trouble, writing a query string, to update a specific sql record. I have all my respective values stores in strings, and whebn i add them (values as parameters), it will convert the primary id to an int. So far, so good.

The problem lies in my query string it self. I can do deleting and creation of sql records (select and insert) yet the problem here, lies in updating. That i have no real experience in.

Now... For the query string that i have all ready...

SqlCommand DerGemmesMedarbejder = new SqlCommand("UPDATE MyTableInQuestion VALUES (@Tittel, @FuldeNavn, @MailAdresse, @TelefonNummer, @MedarbejderType) WHERE PersonaleID = @PersonaleID_FraRepeateren", GemDetAendredeIndhold);

I just can not seem to get it right. The debugger is telling me that the problem is "incorrect syntax near jeyword 'VALUES'

4 Answers 4

4

Try this

SqlCommand DerGemmesMedarbejder = new SqlCommand("UPDATE MyTableInQuestion set title=@Tittel, FuldeNavn=@FuldeNavn, ... WHERE PersonaleID = @PersonaleID_FraRepeateren", GemDetAendredeIndhold);
Sign up to request clarification or add additional context in comments.

Comments

2

Try this query -

UPDATE MyTableInQuestion 
SET 
      Tittel = @Tittel
    , FuldeNavn = @FuldeNavn
    , MailAdresse = @MailAdresse
    , TelefonNummer = @TelefonNummer
    , MedarbejderType = @MedarbejderType
WHERE PersonaleID = @PersonaleID_FraRepeateren

1 Comment

Sorry... Forgot "Tittel" not "@Tittle" in Tittle=@Tittle.
0

Your syntax for update command is not valid. You may confused with Insert and Update command

Update command would be like this

UPDATE MyTableInQuestion set title=@Tittel, FuldeNavn=@FuldeNavn where PersonaleID = @PersonaleID_FraRepeateren

3 Comments

FuldeNavn=@FuldeNavn Should be TheStringNameIUse=@FuldeNavn ?
@FuldeNavn is the parameter which holds the value, which will used as a value of FuldeNavn column.
So. If i draw this "DerGemmesMedarbejder.Parameters.AddWithValue("@Tittel", Tittel_DerSkalGemmes);" from my strings that holds the values to be stored, then i should be ok with using "Tittle=@Tittle", as the values are drawn from my variables? (strings and an int)
0

Because the syntax is incorrect. Syntax here

For update statements, you must change your query to this:

UPDATE MyTableInQuestion SET Column1 = @Tittel, Column2 = @FuldeNavn, Column3 = @MailAdresse, Column4 = @TelefonNummer, Column5 = @MedarbejderType WHERE PersonaleID = @PersonaleID_FraRepeateren"

Where Column1-5 is your column names

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.