Sql Update Statement?
What's Wrong in this SQL Update Statement
Table Name = Register
Column 1 = ID [int]
Column 2 = SaveYear [int]
Column 3 = From [text]
Column 4 = SaveDate [DateTime/Short Date Only]
Column 5 = Subject [text]
Column 6 = Destination [text]
Column 7 = Note [text]
string updateQuery = "UPDATE Register SET SaveYear = " + yearComboBox.Text + " , From = '" + fromTextBox.Text + "', SaveDate= '" + Convert.ToDateTime( dateTimePicker1.Value.ToShortDateString()).ToShortDateString() + "', Subject = '" + subjectRichTextBox.Text + "', Destination = '" + destinationComboBox.Text + "', Note = '" + notesTextBox.Text + "' WHERE ID = " + Convert.ToInt32(dealTextBox.Text) + " ";
I Received a Syntax Error in Update Statement
- MajbuddinLv 48 years agoFavorite Answer
There are lots of errors in your code.
1. what drop down list value i,e combo box's value is to be set in the table, that u cannot write like this.
you have to update the table entry with the selected value of the combo box.
for this at first, store the selected value of combo box in a variable.
let your combo box name is combo1 then write this.
Write all drop down selected values like this, unless it is text box.
To write update query, write it using Prepared Statement method.
String updateQuery="UPDATE Register SET SaveYear =?,from=? and so on";
where year= a variable where you have stored year value.
from=a variable where you have stored from value.
hope this is clear to u.Source(s): My own experience
- etienneLv 44 years ago
Is the subject something like this? one million) Order created (row inserted so as table) -> replace onOrder value in inventory table 2) Order won (row as much as date so as table) -> replace (shrink) onOrder and (strengthen) onHand values in inventory table if so, you need to try this via a pair of triggers against the orders table, one an insert set off and the different an replace set off (plus maybe a nil.33 delete set off to deal with cancelled orders.) yet another risk is via a transaction as suggested above.
- TheMadProfessorLv 78 years ago
Just as a starter, your .Text attributes are just that - text. To place them in int or datetime fields, you have to convert them to a compatible value.
- Serge MLv 68 years ago
FROM is a keyword of SQL. Use [FROM] or something like this depending on DBMS.