We help IT Professionals succeed at work.
Get Started

Parameterized Query which was not supplied.

noobe1 asked
Last Modified: 2012-05-05
Hi Experts,
I have a gridview that is bound to an objectdatasource. The gridview has 3 columns: ID, Title and SubTitle.

When I edit a row, I will get the following error if I leave the SubTitle textbox blank.
Parameterized Query '(@Title nvarchar(9),@SubTitle nvarchar(4000),@ID nvarchar(3))UPD' expects parameter @SubTitle, which was not supplied.

I will get a similar error if I leave the Title textbox blank.

How do I fix it?

Imports System.Data.SqlClient
Imports System.Configuration
Public Class Books
    Public Shared Sub UpdateBooks(ByVal Title As String, ByVal SubTitle As String, ByVal ID As String)
        Dim connection As SqlConnection = StartConnection()
        Dim sSqlQuery As String = ""
        sSqlQuery = "UPDATE dxBooks SET Title = @Title, SubTitle = @SubTitle WHERE (ID = @ID)"
        Dim Cmd As New SqlCommand(sSqlQuery, connection)
        Cmd.Parameters.AddWithValue("@Title", Title)
        Cmd.Parameters.AddWithValue("@SubTitle", SubTitle)
        Cmd.Parameters.AddWithValue("@ID", ID)
    End Sub
End Class

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE