DataAdapter with Parameter problem

D

DesCF

When I run the following code everything works fine (which proves the
stored procedure and the parameter:

Dim cmdSQL As New SqlCommand
cmdSQL.CommandType = CommandType.StoredProcedure
cmdSQL.CommandText = "bdl_CustomerOrders_SELECT"
cmdSQL.Connection = mcnnSQL
Dim prm As New SqlParameter()
prm.ParameterName = "@CustomerID"
prm.Value = Me.cboCustomerSELECT.SelectedValue
prm.Direction = ParameterDirection.Input
cmdSQL.Parameters.Add(prm)
mcnnSQL.Open()
Dim dr As SqlDataReader
dr = cmdSQL.ExecuteReader()
While dr.Read
Debug.WriteLine(dr.Item(0).ToString)
End While
dr.Close()


However, when I run the following code I get the error message:
Incorrect syntax near 'bdl_CustomerOrders_SELECT' at the last line:
sda.Fill(ds, "CustomerOrders")
Thoughts anyone ?


Dim sda As New SqlDataAdapter("bdl_CustomerOrders_SELECT", mcnnSQL)
Dim prm As SqlParameter =
sda.SelectCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5,
"CustomerID")
prm.Direction = ParameterDirection.Input
prm.SqlValue = Me.cboCustomerSELECT.SelectedValue
sda.TableMappings.Add("Table1", "CustomerOrders")
Dim ds As New DataSet()
sda.Fill(ds, "CustomerOrders")




Des
 
M

Miha Markic

Most probably you are missing this line:
sda.SelectCommand.CommandType = CommandType.StoredProcedure

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


When I run the following code everything works fine (which proves the
stored procedure and the parameter:

Dim cmdSQL As New SqlCommand
cmdSQL.CommandType = CommandType.StoredProcedure
cmdSQL.CommandText = "bdl_CustomerOrders_SELECT"
cmdSQL.Connection = mcnnSQL
Dim prm As New SqlParameter()
prm.ParameterName = "@CustomerID"
prm.Value = Me.cboCustomerSELECT.SelectedValue
prm.Direction = ParameterDirection.Input
cmdSQL.Parameters.Add(prm)
mcnnSQL.Open()
Dim dr As SqlDataReader
dr = cmdSQL.ExecuteReader()
While dr.Read
Debug.WriteLine(dr.Item(0).ToString)
End While
dr.Close()


However, when I run the following code I get the error message:
Incorrect syntax near 'bdl_CustomerOrders_SELECT' at the last line:
sda.Fill(ds, "CustomerOrders")
Thoughts anyone ?


Dim sda As New SqlDataAdapter("bdl_CustomerOrders_SELECT", mcnnSQL)
Dim prm As SqlParameter =
sda.SelectCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5,
"CustomerID")
prm.Direction = ParameterDirection.Input
prm.SqlValue = Me.cboCustomerSELECT.SelectedValue
sda.TableMappings.Add("Table1", "CustomerOrders")
Dim ds As New DataSet()
sda.Fill(ds, "CustomerOrders")




Des
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top