Can anybody see where this is failing?
Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
da.SelectCommand.Parameters.Add("@CustomerID",
SqlDbType.VarChar, 40)
Dim ds As New DataSet
da.SelectCommand.Parameters("@CustomerID").Value = myCustID
da.Fill(ds, "Customers")
End Sub
The error that I am getting on the fill command is: "The variable name
'@CustomerID' has already been declared. Variable names must be unique
within a query batch or stored procedure."
The dataadapter being referenced (da) is on the form with a
selectcommand set up in the query builder as such:
SELECT OrderID, CustomerID, OrderDate, EmployeeID
FROM Orders
WHERE CustomerID = @CustomerID
I can't seem to pass this value into the query correctly. I've tried
taking the @ signs out of the code, but exact same error.
thanks, Ken 11 4411
"Ken" <fk****@yahoo.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Can anybody see where this is failing?
Private Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
da.SelectCommand.Parameters.Add("@CustomerID",
SqlDbType.VarChar, 40)
Dim ds As New DataSet
da.SelectCommand.Parameters("@CustomerID").Value = myCustID
da.Fill(ds, "Customers")
End Sub
The error that I am getting on the fill command is: "The variable name
'@CustomerID' has already been declared. Variable names must be unique
within a query batch or stored procedure."
You're adding a new parameter every time you click Button2! Possibly it
already has the parameter depending on how it is setup. Generally I just
create these things in code instead of putting them on the form but presume
it's possible to add params at design time.
Michael
>
You're adding a new parameter every time you click Button2! Possibly it
already has the parameter depending on how it is setup. Generally I just
create these things in code instead of putting them on the form but presume
it's possible to add params at design time.
Michael
That's what I was afraid of. I'd love to do the whole thing in code,
but I'm using VB Express, and it doesn't recognize the New
SqlDataAdapter as a valid command. That's why I put the adapter on
the form instead. Any idea how I can pass the parameter value from
the code into the query?
Thanks alot for the response,
Ken
>
You're adding a new parameter every time you click Button2!
That's what I was afraid of.
Possibly it already has the parameter depending on how it is setup. Generally I just
create these things in code instead of putting them on the form but presume
it's possible to add params at design time.
I'd love to do this in code, but I'm using VB Express, and it doesn't
recognize New SqlDataAdapter as a valid command. That's why I put the
adapter on the form instead. Any idea as to how I can pass the
parameter value into the query as structured above? Or is there a
better way to do this? The value is originally coming from a textbox
on the form.
Thanks for your help, Michael
Ken
You're adding a new parameter every time you click Button2!
That's what I was afraid of.
Possibly it already has the parameter depending on how it is setup. Generally I just
create these things in code instead of putting them on the form but presume
it's possible to add params at design time.
I'd love to do it in code, but I'm using VB Express, which doesn't
recognize the New SqlDataAdapter command. Any ideas how I can pass
the param value into the sql on the form da? Or any other better
ideas?
Thanks for your help, Michael.
Ken
"Ken" <fk****@yahoo.comwrote in message
news:11**********************@u32g2000prd.googlegr oups.com...
>You're adding a new parameter every time you click Button2!
That's what I was afraid of.
>Possibly it already has the parameter depending on how it is setup. Generally I just create these things in code instead of putting them on the form but presume it's possible to add params at design time.
I'd love to do it in code, but I'm using VB Express, which doesn't
recognize the New SqlDataAdapter command. Any ideas how I can pass
the param value into the sql on the form da? Or any other better
ideas?
Thanks for your help, Michael.
Ken
Surely it allows you to create a new data adaptor? The one designed on the
form only generates code to do just that anyway.
If you still want to leave it on the form then you could just remove the
line that adds the parameter. Otherwise you could move the line that creates
the parameter to form_load so it gets executed only once.
>
Surely it allows you to create a new data adaptor? The one designed on the
form only generates code to do just that anyway.
I think that I might have found it. I was trying "dim da as New
SqlDataAdapter", but that wasn't valid.
I found "dim da as New SqlClient.SqlDataAdapter". I'm going to play
around with that to see if it will allow me to do this all within the
procedure.
I'll repost if I get stuck. Thanks for your help.
Sorry for the multiple posts. The board didn't display my replies, so
I thought they weren't posting.
Ken
"Ken" <fk****@yahoo.comwrote in message
news:11*********************@c18g2000prb.googlegro ups.com...
>
>Surely it allows you to create a new data adaptor? The one designed on the form only generates code to do just that anyway.
I think that I might have found it. I was trying "dim da as New
SqlDataAdapter", but that wasn't valid.
I found "dim da as New SqlClient.SqlDataAdapter". I'm going to play
around with that to see if it will allow me to do this all within the
procedure.
You need to add the vb equivelant of C#'s "Using SqlClient" to the top of
your form.
Michael
"Michael C" <no****@nospam.comwrote in message
news:OK****************@TK2MSFTNGP03.phx.gbl...
"Ken" <fk****@yahoo.comwrote in message
news:11*********************@c18g2000prb.googlegro ups.com...
>>
>>Surely it allows you to create a new data adaptor? The one designed on the form only generates code to do just that anyway.
I think that I might have found it. I was trying "dim da as New SqlDataAdapter", but that wasn't valid.
I found "dim da as New SqlClient.SqlDataAdapter". I'm going to play around with that to see if it will allow me to do this all within the procedure.
You need to add the vb equivelant of C#'s "Using SqlClient" to the top of
your form.
Michael
That would be
Imports System.Data.SqlClient
Robin S.
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:vK******************************@comcast.com. ..
That would be
Imports System.Data.SqlClient
Thanks. My statement was missing the System.Data part :-)
Michael
Even if VB Express does not do something you can always use the compiler
from the command prompt and compile the code with vbc.exe.
If you are using SqlClient, you can as well directly assign the value to
the da object as your command object already knows the @customerid
parameter.
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
*** Sent via Developersdex http://www.developersdex.com ***
You're welcome. I find the search box on the Object browser to be
invaluable when looking for what I need to include. :-)
Robin S.
-----------------------------
"Michael C" <no****@nospam.comwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:vK******************************@comcast.com. ..
>That would be
Imports System.Data.SqlClient
Thanks. My statement was missing the System.Data part :-)
Michael This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nashat Wanly |
last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and
Visual C# .NET
View products that this article applies to.
This article was previously published under Q310070
For a Microsoft...
|
by: gary b |
last post by:
Hello
When I use a PreparedStatement (in jdbc) with the following query:
SELECT store_groups_id
FROM store_groups
WHERE store_groups_id IS NOT NULL
AND type = ?
ORDER BY group_name
|
by: deko |
last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of
new to parameterized queries, so I'm sure I'm missing something simple.
Set qdfs = db.QueryDefs
Set qdf =...
|
by: deko |
last post by:
Is it possible to build a parameterized query from another parameterized
query?
I've tried two variations of this and can't seem to get it to work (using
DAO). Any suggestions welcome!
I...
|
by: anony |
last post by:
Hello,
I can't figure out why my parameterized query from an ASP.NET page is
dropping "special" characters such as accented quotes & apostrophes, the
registered trademark symbol, etc. These...
|
by: JSheble |
last post by:
After building a parameterized ADO query, is there a method or a statement
where you could see the actual query, with the parameterized values
included??
--
Using Opera's revolutionary e-mail...
|
by: Roland Hall |
last post by:
In Access you use "*" + + "*", + can be replaced with &
Calling a parameterized query in Access requires % be used in place of *,
however, all that I have read show dynamic SQL passed to Access:
...
|
by: TF |
last post by:
This group came through for me last time so here we go again. My page
shows paint colors, brand name, product code, etc in a gridview with
the background matching the paint color. Several links on...
|
by: xlar54 |
last post by:
Is there a way to see the exact SQL being generated from a
parameterized query? I am using this technique but am getting some
strange SQL errors during execution and I would like to see the final...
|
by: mcalex |
last post by:
Hi, I'm having trouble trying to populate a list box with data from a parameterized query.
If I set the rowsource property to the query name, when the form opens I get the parameter values dialog,...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |