PC Review


Reply
Thread Tools Rate Thread

DataAdapter with Parameter problem

 
 
DesCF
Guest
Posts: n/a
 
      18th Jul 2007

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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
 
Reply With Quote
 
 
 
 
Miha Markic
Guest
Posts: n/a
 
      23rd Jul 2007
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/

"DesCF" <(E-Mail Removed)> wrote in message newsp.tvoa30jiupgxg0@descstar...

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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataAdapter with Parameter problem DesCF Microsoft VB .NET 1 18th Jul 2007 07:56 PM
add parameter to dataadapter on load =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= Microsoft ADO .NET 1 20th Apr 2005 03:35 PM
Output Parameter always 0 when used with a dataadapter Tommy Microsoft ADO .NET 1 4th May 2004 07:18 PM
DataAdapter Parameter question Darwin S. Microsoft ADO .NET 5 13th Nov 2003 05:03 PM
Passing a parameter to DataAdapter ZoeNeedsHelp Microsoft Dot NET 0 13th Nov 2003 02:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.