SQL update boolean

johnuk4

Active member
Joined
Feb 18, 2006
Messages
25
Programming Experience
Beginner
Hi, I am having a problem updating my database when the user changes a boolean value in my datagrid. Basically i load a dataset into my datagrid from here the user can click on the yes/no box to say they have read it. The user then clicks an update button with the following code which i got from another article:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] UpdateDatabase()
conn.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cmd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand
cmd.CommandText = "UPDATE DatabaseTable SET Resolve_Flag = "No", columnname = Resolve_Flag";
cmd.Connection = conn
cmd.parameters.add("@columnname1", oledbtype.Boolean, fieldsize,source column name [/SIZE][SIZE=2][COLOR=#0000ff]as[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2])
 
conn.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

I am having a few problems understanding this code and how to apply it to mine. Could some possibly give me some guidance with this.

Thanks very much

John
 
VB.NET:
cmd.CommandText = "UPDATE DatabaseTable SET Resolve_Flag = "No", columnname = Resolve_Flag"

i think above code have some problem change it to

VB.NET:
cmd.CommandText = "UPDATE DatabaseTable SET Resolve_Flag = 'No', columnname = 'Resolve_Flag'"
 
Last edited by a moderator:
That code is wrong for several reasons.

1. You don't put anything in double quotes.
2. Single quotes are only for text values.
3. You're adding a parameter to the command but there are no parameters in the SQL code.
4. Valid boolean values are True and False.
5. You have no WHERE clause so how does it know what record to update?
VB.NET:
Dim myCommand As New OleDbCommand("UPDATE Table SET ResolveFlag = @ResolveFlag WHERE ID = @ID", myCommand)

myCommand.Parameters.Add("@ResolveFlag", myCheckBox.Checked)
 
Back
Top