Results 1 to 3 of 3

Thread: sql UPDATE statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    116

    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

  2. #2
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    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

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width