473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to add adapters

I'm trying to use three stored procedures and three adapters but don't
know how to set it up. This is giving me errors. Can someone assist
me please.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainUserConnectionString").Con nectionString)

Dim cmdALL As New Data.SqlClient.SqlCommand
Dim cmdTopic As New Data.SqlClient.SqlCommand 'cmd for 2nd
stored procedure
Dim cmdMedia As New Data.SqlClient.SqlCommand ' 3rd stored
procedure
With cmdALL
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetAllTopics"

If DropDownList2.SelectedValue = "-1" Then
.Parameters.AddWithValue("@Type",
DropDownList2.SelectedValue)
End If
.Connection = conn

End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdALL)

With cmdTopic
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetByTopic"

If DropDownList3.SelectedIndex 0 Then
.Parameters.AddWithValue("@classificationid",
Integer.Parse(DropDownList2.SelectedValue))
End If
.Connection = conn
End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdTopic)

With cmdMedia
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetByMedia"

If DropDownList3.SelectedValue 0 Then
.Parameters.AddWithValue("@Mediaid",
DropDownList3.SelectedValue)
End If
.Connection = conn
End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdMedia)

Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try
Jan 15 '08 #1
9 1009
Please tell us what the error is that you're getting and on what line.

Ray Costanzo

"JJ297" <nc***@yahoo.comwrote in message
news:d4**********************************@v29g2000 hsf.googlegroups.com...
I'm trying to use three stored procedures and three adapters but don't
know how to set it up. This is giving me errors. Can someone assist
me please.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainUserConnectionString").Con nectionString)

Dim cmdALL As New Data.SqlClient.SqlCommand
Dim cmdTopic As New Data.SqlClient.SqlCommand 'cmd for 2nd
stored procedure
Dim cmdMedia As New Data.SqlClient.SqlCommand ' 3rd stored
procedure
With cmdALL
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetAllTopics"

If DropDownList2.SelectedValue = "-1" Then
.Parameters.AddWithValue("@Type",
DropDownList2.SelectedValue)
End If
.Connection = conn

End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdALL)

With cmdTopic
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetByTopic"

If DropDownList3.SelectedIndex 0 Then
.Parameters.AddWithValue("@classificationid",
Integer.Parse(DropDownList2.SelectedValue))
End If
.Connection = conn
End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdTopic)

With cmdMedia
.CommandType = Data.CommandType.StoredProcedure

.CommandText = "GetByMedia"

If DropDownList3.SelectedValue 0 Then
.Parameters.AddWithValue("@Mediaid",
DropDownList3.SelectedValue)
End If
.Connection = conn
End With

Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdMedia)

Try

conn.Open()

Dim ds As New Data.DataSet
adapter.Fill(ds)

GridView1.DataSource = ds

GridView1.DataBind()

Finally

conn.Close()

End Try

Jan 15 '08 #2
On Jan 15, 9:04*am, "Ray Costanzo" <my first name at lane34 dot
commercialwrote:
Please tell us what the error is that you're getting and on what line.

Ray Costanzo

"JJ297" <nc...@yahoo.comwrote in message

news:d4**********************************@v29g2000 hsf.googlegroups.com...
I'm trying to use three stored procedures and three adapters but don't
know how to set it up. *This is giving me errors. *Can someone assist
me please.
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
* * * *Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager. ConnectionStrings("TrainU*serConnectionString").Co nnectionString)
* * * *Dim cmdALL As New Data.SqlClient.SqlCommand
* * * *Dim cmdTopic As New Data.SqlClient.SqlCommand *'cmd for2nd
stored procedure
* * * *Dim cmdMedia As New Data.SqlClient.SqlCommand ' 3rd stored
procedure
* * * * * *With cmdALL
* * * * * * * *.CommandType = Data.CommandType.StoredProcedure
* * * * * *.CommandText = "GetAllTopics"
* * * * * *If DropDownList2.SelectedValue = "-1" Then
* * * * * * * *.Parameters.AddWithValue("@Type",
DropDownList2.SelectedValue)
* * * * * *End If
* * * * * *.Connection = conn
* * * *End With
* * * *Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdALL)
* * * *With cmdTopic
* * * * * *.CommandType = Data.CommandType.StoredProcedure
* * * * * *.CommandText = "GetByTopic"
* * * * * *If DropDownList3.SelectedIndex 0 Then
* * * * * * * *.Parameters.AddWithValue("@classificationid",
Integer.Parse(DropDownList2.SelectedValue))
* * * * * *End If
* * * * * *.Connection = conn
* * * *End With
* * * *Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdTopic)
* * * *With cmdMedia
* * * * * *.CommandType = Data.CommandType.StoredProcedure
* * * * * *.CommandText = "GetByMedia"
* * * * * *If DropDownList3.SelectedValue 0 Then
* * * * * * * *.Parameters.AddWithValue("@Mediaid",
DropDownList3.SelectedValue)
* * * * * *End If
* * * * * *.Connection = conn
* * * *End With
* * * *Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdMedia)
* * * *Try
* * * * * *conn.Open()
* * * * * *Dim ds As New Data.DataSet
* * * * * *adapter.Fill(ds)
* * * * * *GridView1.DataSource = ds
* * * * * *GridView1.DataBind()
* * * *Finally
* * * * * *conn.Close()
* * * *End Try- Hide quoted text -

- Show quoted text -
Thanks Ray for your help!

I'm getting:
Local variable 'adapter' is already declared in the current block for:
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdTopic)
and
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdMedia)

Jan 15 '08 #3
"JJ297" <nc***@yahoo.comwrote in message
news:20**********************************@l1g2000h sa.googlegroups.com...
I'm getting:
Local variable 'adapter' is already declared in the current block for:
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdTopic)
and
Dim adapter As New Data.SqlClient.SqlDataAdapter(cmdMedia)
That means exactly what it says - you are trying to declare two variables
with the same name within the same scope.

Dim adapter1 As New Data.SqlClient.SqlDataAdapter(cmdTopic)
Dim adapter2 As New Data.SqlClient.SqlDataAdapter(cmdMedia)

should fix it, though it's not particularly elegant or efficient...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 15 '08 #4
"JJ297" <nc***@yahoo.comwrote in message
news:20**********************************@l1g2000h sa.googlegroups.com...
I'm getting:
Local variable 'adapter' is already declared in the current block for:
Give all three adapters different names e.g.
Dim adapter1 As New Data.SqlClient.SqlDataAdapter(cmdTopic)
and
Dim adapter2 As New Data.SqlClient.SqlDataAdapter(cmdMedia)

Jan 15 '08 #5
This conditional seems to be wrong:

If DropDownList2.SelectedValue = "-1" Then

I think you should just add the parameter anyway, as the conditional is
redundant. Get rid of the if line and the end if line and just leave:

..Parameters.AddWithValue("@Type", DropDownList2.SelectedValue)

Jan 15 '08 #6
"JJ297" <nc***@yahoo.comwrote in message
news:81**********************************@m34g2000 hsb.googlegroups.com...

Looking a bit further, it seems your code doesn't actually do anything
anyway. You are passing in the selected value of a dropdown box, and then
ignoring it by having:

if @type = '-1'

In your stored procedure without any query for when it isn't -1.

Jan 15 '08 #7
"JJ297" <nc***@yahoo.comwrote in message
news:91**********************************@l32g2000 hse.googlegroups.com...
I have seven stored procedures to use to populate one gridview. I was
trying to get three working first then I would be able to add the
others.
OK, note that (as explained in my previous post) you don't need two separate
stored procedures to display all records and limited records if the query is
the same, you can either use:

IF @var = -1
BEGIN
-- Select everything
END
ELSE
BEGIN
-- Select limited results
END

Or even better:

SELECT
col1,
col2
FROM
yourtable
WHERE
(@var = -1 OR (col3 = @var))

You also do not need one data adapter and one command object per query if
you are populating the same gridview. Just conditionally set the CommandText
and parameters based on what the user has selected in the drop downs.

Jan 15 '08 #8
On Jan 15, 11:19*am, "Leon Mayne" <leon@rmv_me.mvps.orgwrote:
"JJ297" <nc...@yahoo.comwrote in message

news:91**********************************@l32g2000 hse.googlegroups.com...
I have seven stored procedures to use to populate one gridview. *I was
trying to get three working first then I would be able to add the
others.

OK, note that (as explained in my previous post) you don't need two separate
stored procedures to display all records and limited records if the query is
the same, you can either use:

IF @var = -1
BEGIN
* * -- Select everything
END
ELSE
BEGIN
* * -- Select limited results
END

Or even better:

SELECT
* * col1,
* * col2
FROM
* * yourtable
WHERE
* * (@var = -1 OR (col3 = @var))

You also do not need one data adapter and one command object per query if
you are populating the same gridview. Just conditionally set the CommandText
and parameters based on what the user has selected in the drop downs.
Okay this sounds great Leon. I will use one stored procedure and
then set it up as you have suggested. So the way you are telling me
to set it up is to place all of my code in the one stored procedure
and take care of the if else statements there. Makes sense. I will
try it and get back to you. Thanks!
Jan 15 '08 #9
"JJ297" <nc***@yahoo.comwrote in message
news:b8**********************************@l1g2000h sa.googlegroups.com...
Okay this sounds great Leon. I will use one stored procedure and
then set it up as you have suggested. So the way you are telling me
to set it up is to place all of my code in the one stored procedure
and take care of the if else statements there. Makes sense. I will
try it and get back to you. Thanks!
If you need a hand then zip and mail me the code and I can give it a tweak
for you if I get time one evening.

Jan 15 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Crowe | last post by:
Greetings Everyone: Oracle 9i installed on a sun solaris box. No protocol adapters available. I would greatly appreciate any help from the db gurus on this forum. after bringing up the...
0
by: Paul Steele | last post by:
Is there a reliable way to check for the existence of wireless adapters in a system? I thought it was going to be simple using WMI's Win32_NetworkAdapter class, but the information at MSDN does not...
3
by: Robin | last post by:
When adding a SQL Data Adapter to a page, is possible to configure it use a connection string in code? As I have found it regenerates the code each time and of the adapters are modified and does...
3
by: Maniaque | last post by:
Does anybody knows, how can I address multiply network adapters on one computer? I've looked up through classes reference and found nothing. Thanks in advance. -- .... blood, sugar, sex,...
0
by: dimpy | last post by:
Hi everyone, I am using some big size data adapters to fill datasets to be sent to a web service. Now every time i get an error in datatype or constraints violations while filling the dataset, I...
0
by: Paul Craig | last post by:
Hi everyone, I have recently upgraded several of my projects from Visual Studio 2003 to 2005 and everything went across quite smoothly. The main problem that I am having is I have used SQL Data...
1
by: Justin | last post by:
We decided to upgrade to 2005 and upgrade our components. After fixing a few odds and end the upgrade was complete and our project was working fine. We didn't run into problems until we needed to...
1
by: Michael | last post by:
Hello, I have been reading about the new CSS Control Adapters. (@ http://weblogs.asp.net/scottgu/default.aspx) And was wondering if any one can tell me what the point is. I downloaded the sample...
2
by: a.mustaq | last post by:
Hi All, My Client wantsb to develop the site using CSS Control adapters. I go thru number articles on web, but could not understand how they are worthfull. What are theire merits over <table>...
4
by: =?Utf-8?B?TWFydGlu?= | last post by:
In Device Manager under Network Adapters, nearly all (about 20) items have a yellow warning symbol. The first item, Microsoft 6to4 Adapter says driver is up-to-date BUT says "This device is not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.