0

I'm having problems trying to fill in the DataSet using SQL Server 2005. Basically I have a table in SQL Server and I want to retrieve those information and be able to display it in a web browser using DataSet. Whenever I run my code I always get error message:

Line 1: Incorrect syntax near '?'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '?'.

Source Error:


Line 16: ProductDA = New SqlDataAdapter("Select * From Surfzone Where SBID = ?", objConn)
Line 17:
Line 18: ProductDA.Fill(ProductDS)
Line 19:
Line 20: Return ProductDS.Tables(0)

-------------------------------------------------------------------------------

Here's my code:

Imports System.Data
Imports System.Data.SqlClient

Namespace SurfZone

    Public Class Products

        Public Function RetrieveProductData(ByVal IDProduct As Integer) As DataTable

            Dim objConn As SqlConnection
            Dim ProductDA As SqlDataAdapter
            Dim ProductDS As New DataSet

            objConn = New SqlConnection("Data Source=0.0.0.0;Initial Catalog=DBNAME;Persist Security Info=TRUE;User ID=USERID;Password=PASSWORD")

            ProductDA = New SqlDataAdapter("Select * From TABLENAME Where ID = ?", objConn)

            ProductDA.Fill(ProductDS)

            Return ProductDS.Tables(0)

        End Function

    End Class

End Namespace

---------------------------------------------------------------------------

Any ideas??

Thanks!

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by aspusers
0

You need to pass parameter value.

....
Dim Cmd as new SqlCommand("Select * From TABLENAME Where ID = @id", objConn)
Cmd.Parameters.Add(new SqlParameter("@id",SqlDbType.Int)).Value=10
ProductDA = New SqlDataAdapter(Cmd)
....
0

Hi adatapost,

Thank you so much for your reply! That worked like a charm! I adjusted some parts of the code because I'm using a query string being passed from the asp server page. The part of the code that I changed was:

Dim Cmd As New SqlCommand("Select * From TABLENAME Where ID = @id", objConn)
Cmd.Parameters.Add(New SqlParameter("@id", SqlDbType.Int)).Value = IDProduct

Thanks again for your quick response! I greatly appreciate it! :)

Regards

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.