Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

SQL Update help please

$
0
0

Hello all

I’m having trouble with a back end SQL UPDATE query. What I want to do is update a checkbox on a button click. The checkbox should belong to the overall record that is chosen by the user. The user will select a Registration from a dropdown box. (note the registration is unique in my system) - The Checkbox is called Departed.

So in the table we have

Index = Integer (Pri Key)

Registration = Varchar 50

Departed = Boolean (Checkbox)

 

In simple terms this is what I’m trying to achieve,  but clearly the syntax is wrong 

Dim Sql As String = "UPDATE VAP_table" & "SET Departed = @Departed" & "WHERE Registration = Dropdownbox1.selecteditem.tostring"

The code I have will work if you drop the 'Where' statement element, but of course ALL the records Departed checkbox are set then.

Here is the code I have - Could anyone help me with the line that I'm having trouble with?

 

ProtectedSub Button2_Click(ByVal sender AsObject,ByVal e AsEventArgs)Handles Button2.Click

Dim departed_flag AsBoolean = True

Dim conn AsString = ConfigurationManager.ConnectionStrings("Connectionstring3").ConnectionString

Dim connection AsSqlConnection = NewSqlConnection(conn)

' PW - Works to set all  -    Dim Sql As String = "UPDATE [VAP_table]" & "SET [Departed] = @Departed"

Dim Sql AsString = "UPDATE [VAP_table]"&"SET [Departed] = @Departed"&"WHERE [Registration] = Dropdownbox1.selecteditem.tostring"

Dim cmd AsSqlCommand = NewSqlCommand(Sql, connection)

cmd.Parameters.AddWithValue("@Departed", departed_flag)

        connection.Open()

        cmd.ExecuteNonQuery()

        connection.Close()

   

EndSub

 

 


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>