0

Hi im having a problem with the code,i'm not being able to figure out the problem..if anyone could help..thank you

Protected Sub btnActive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnActive.Click

Dim connectionString As String = "Data Source = .\SQLEXPRESS; AttachDbFileName=|DataDirectory|Petite.mdf; Integrated Security=True; User Instance=True"

Dim conn As SqlConnection = New SqlConnection(connectionString)

Dim cmd As SqlCommand

Dim myupdate As String

    myupdate = " UPDATE Seller Set Status='active' WHERE Username=@Username"

        cmd = New SqlCommand(myupdate, conn)
    cmd.Parameters.AddWithValue("@Username", Session("Username"))

        conn.Open()
        cmd.ExecuteNonQuery()

    MsgBox("Account has been successfully activated!!")

    Response.Redirect("AdminSellers.aspx")
        conn.Close()
End Sub

And I'm getting this error

The parameterized query '(@username nvarchar(4000)) UPDATE Seller Set Status='deactivated' expects the parameter '@username', which was not supplied.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    Is there a possibility that `Session("Username")` is `Nothing` - I suspect that will trigger this behaviour – James Thorpe Nov 07 '14 at 17:26
  • 5
    According to the message, the error is when you call the 'deactivated' query. You are showing us the 'active' query. Maybe the code isn't the same... – LarsTech Nov 07 '14 at 17:29
  • wow, sharp eyes @LarsTech ! – Ňɏssa Pøngjǣrdenlarp Nov 07 '14 at 17:41
  • 1
    A Session variable passed to AddWithValue? Uhm it stinks, you are on a landmine here, hope for the best. I suggest to create a parameter specifying exactly type and size and convert the Session variable to an appropriate C# type – Steve Nov 07 '14 at 18:14

0 Answers0