|
-
Jan 4th, 2010, 12:40 AM
#1
Thread Starter
Lively Member
sql UPDATE statement
In a SQL UPDATE statement, how to i "set" a field to empty? (because it was occupied before).
i get a syntax error (missing operator) that points to my sql string
this is the update command i am using but its not working...
Code:
"UPDATE trips set billedamount = '', billstatus = 'unbilled' WHERE tripid = " & DataGridView1.CurrentRow.Cells("tripid").Value.ToString & ""
as you can see, all i want to do is make the billstatus field = "unbilled"
and make the "billedamount" field = nothing(empty/null/whatever)
any help is appreciated
-
Jan 4th, 2010, 02:35 AM
#2
Fanatic Member
Re: sql UPDATE statement
Though i am not sure but you may try out this:
Code:
UPDATE trips set billedamount = @billedamount, billstatus = @billstatus WHERE tripid = " & DataGridView1.CurrentRow.Cells("tripid").Value.ToString & "
cmd.parameters.AddwithValue("@billedamount",textbox1.text)
cmd.parameters.AddwithValue("@billstatus",textbox2.text)
cmd.executenonquery
then leave the textbox1 empty..............
reply whether it works or not
-
Jan 4th, 2010, 03:40 AM
#3
Re: sql UPDATE statement
Technically you are setting it to empty.... what you've set it to is an empty string. Presumably though, what you are trying to do is set it to NULL.
Based on the previous code sample....
Code:
UPDATE trips set billedamount = @billedamount, billstatus = @billstatus WHERE tripid = " & DataGridView1.CurrentRow.Cells("tripid").Value.ToString
If textbox1.text = "" Then
cmd.parameters.AddwithValue("@billedamount",DBNULL.Value)
Else
cmd.parameters.AddwithValue("@billedamount",textbox1.text)
End If
If textbox2.text = "" then
cmd.parameters.AddwithValue("@billstatus",dbnull.value)
else
cmd.parameters.AddwithValue("@billstatus",textbox2.text)
end if
cmd.executenonquery
-tg
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
|