Need help with an ADO style update.

EStallworth

Well-known member
Joined
Aug 14, 2006
Messages
75
Location
Destin, FL
Programming Experience
Beginner
Can anyone tell me why this is not updating my SQL database.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] updatestatus [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand([/SIZE][SIZE=2][COLOR=#800000]"UPDATE Org SET Status ='@Status' WHERE AcctCode = '@AcctCode'"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].cn1)   [/SIZE]
[SIZE=2]updatestatus.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]"AcctCode"[/COLOR][/SIZE][SIZE=2], ComboBox1.Text)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Label67.Text = [/SIZE][SIZE=2][COLOR=#800000]"Active"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] updatestatus.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]"@Status"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"I"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] Label67.Text = [/SIZE][SIZE=2][COLOR=#800000]"Inactive"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2] updatestatus.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]"@Status"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"A"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
 
 
 
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Me[/COLOR][/SIZE][SIZE=2].cn1.Open()[/SIZE]
[SIZE=2] updatestatus.ExecuteNonQuery()[/SIZE]
[SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception[/SIZE]
[SIZE=2] MessageBox.Show(ex.Message)[/SIZE]
[SIZE=2][COLOR=#0000ff]Finally[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] Me[/COLOR][/SIZE][SIZE=2].cn1.Close()[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
 
Remove the tick marks from around your parameters.... they are not necessary...
VB.NET:
'@Status' WHERE AcctCode = '@AcctCode'

should be

VB.NET:
@Status WHERE AcctCode = @AcctCode


-tg
 
That did it! Thx man. I used the tick marks because of the way the query builder formats it. I am still getting used to writing the queries myself.
 
the query builder doesnt ever do that? Putting the apostrophes around the parameter names means a string, containing that text: @AcctCode


i.e. it wont create a parameter any more than this:

myTextBox.Text = "Dim i as New Integer"

will create an integer called i..

perhaps you are seeing the builder put ` ` marks around..





`is very different to '


One is above TAB on an English keyboard
The other is near right shift..
 
Back
Top