We help IT Professionals succeed at work.
Get Started

Parameterized Query which was not supplied.

noobe1
noobe1 asked
on
2,842 Views
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?
Thanks


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)
        Cmd.ExecuteNonQuery()
        connection.Close()
    End Sub
End Class

Open in new window

Comment
Watch Question
Commented:
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