Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Where and how to declare SQLConnection value in a module

Posted on 2005-03-23
3
Medium Priority
?
261 Views
Last Modified: 2008-03-17
I have a module which will hold many diffrent functions to populate diffrent dropdown boxes. My problem is how and where do i define
stuff like this

SqlConnection1.ConnectionString = "workstation id=""APONNATHXP-HP"";packet size=4096;user id=sa;data source=""SQL-HUMDM" & _
            """;persist security info=False;initial catalog=icc"

            sqlGetDropDownValues.CommandText = "[tblLookup_SEL]"
            sqlGetDropDownValues.CommandType = System.Data.CommandType.StoredProcedure
            sqlGetDropDownValues.Connection = SqlConnection1
            sqlGetDropDownValues.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
            sqlGetDropDownValues.Parameters.Add(New System.Data.SqlClient.SqlParameter("@lookupid", System.Data.SqlDbType.Char, 20, "lookupid"))



if i put it within the function or sub it executes the code over and over and add's the same SqlParameter to the system. That causes me to have a invalid amount of arguments and fail the sub / function. is there a part in a code module where i can declare this just like in a form
and if so how...
0
Comment
Question by:AlexPonnath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:p_sie
ID: 13616507
Your question is not so clear to me, but you could remove the parameters first

use :

sqlGetDropDownValues.Parameters.RemoveAt(ParameterName)

for all your parameters before you add the parameters...

Good luck,

P_Sie
0
 

Author Comment

by:AlexPonnath
ID: 13616526
i am looking more for an reusable code so that it does not create a global parm, like it does in a module.
i want the scope to be for this single execution of the code..
0
 
LVL 5

Accepted Solution

by:
soumya_parida earned 2000 total points
ID: 13618889
You can do this, in each function declare its own array pf parameters like
Dim params(2) As System.Data.SqlClient.SqlParameter
params(0) = new System.Data.SqlClient.SqlParameter
'Set the values for al the parameters.

Then assign it to the parameters of  the command.
sqlGetDropDownValues.Parameters  = params

So everytime you  call a function the parameters collection would be reassigned and would lose the previous values.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question