473,387 Members | 1,481 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,387 software developers and data experts.

Passing List values as Stored Procedure Parameters (SQL 2000, NET 2.0)

Hi,

How can I pass values from a List as stored procedure parameters?
[0] name= "Smith", age = 21
[1] name="Brown", age =46
[2] name="White", age=28
...


Expand|Select|Wrap|Line Numbers
  1. // data added to the List
  2.  myDetailsPair.Add(new myPair(a, b));
  3.  
  4. // trying to pass values
  5.     cmd_personalDetails.Parameters.Add("@name", SqlDbType.VarChar).Value = Convert.ToString(a);
  6.  
  7.     cmd_personalDetails.Parameters.Add("@age", SqlDbType.Int).Value = Convert.ToInt32(b);
  8.  
  9. .Value = a //does is not right
  10. .Value = myPair.name //is not right
Or is there an easier solution?
I am using List because I need to pair data from 2 different sources together.
Jun 1 '07 #1
2 3640
Any suggestion any one?
Jun 1 '07 #2
nateraaaa
663 Expert 512MB
Sounds like you should insert the data into a hashtable so that you can reference the Key Value pairs within the hashtable. See the following site for using hashtables in 2.0.

http://www.c-sharpcorner.com/UploadFile/pradeep.tiwari/PradeepTiwariHashtable11072006072247AM/PradeepTiwariHashtable.aspx?ArticleID=2548f7ef-c9f2-4259-969e-713d8b4d297f

My thought here is that you would loop through your dataset or datatable and check to see if the hashtable contains the value yet. If not add the values you want to the hashtable.

Here is an example.
Hashtable branches = new Hashtable();
Expand|Select|Wrap|Line Numbers
  1. foreach(DataRow row in data.Tables[0].Rows)
  2. {
  3. if(!branches.ContainsKey(row["branch_id"]))
  4. {
  5. branches.Add(row["branch_id"], row["branch_email"]);
  6. }
  7. }
  8.  
  9. foreach(DictionaryEntry entry in branches)
  10. {
  11.   //Pass the Key and Value to your stored procedure. The Key is the first column in your hashtable the Value is the second column in the hashtable. 
  12. //NOTE: The hashtable will not output the items in the same order that they were inserted into the hashtable. This is because the hashtable uses an algorithm to increase the speed of searching.
  13.   usp_stored_proc_name(entry.Key.ToString(), entry.Value.ToString());
  14. }
Hope this helps.

Nathan
Jun 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
1
by: CG | last post by:
I'm trying to pass parameters to an extended stored procedure, to no avail. I would like to pass two integers to the dll and I have the following three snippets: 1. The C++ portion of the dll:...
2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
10
by: Resant | last post by:
I have a query : Exec 'Select * From Receiving Where Code In (' + @pCode + ')' @pCode will contain more than one string parameter, eg : A1, A2, A3 How can i write that parameters, I try use :...
8
by: Mark Flippin | last post by:
This is for a reporting problem using: Access 2000 SQL Server 2000 Both at SP3 I've a stored procedure in SQL Server 2000 which builds a result set from a disparate set of tables, utilizing...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
9
by: anilcool | last post by:
Hi all, Another novice question. I want to insert multiple records into my DB2 database using stored procedure but I do not know how many I would like to insert at any given time. Each record...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
0
by: htenay | last post by:
I need to be able to define an array in Java and pass it on to SQL stored procedure. I am new to store proc and found a lot of helpful tutorials on Google but found none that passes parameter of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
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...
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
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...

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.