473,320 Members | 2,080 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,320 software developers and data experts.

Exporting selected ArrayList values to SQL Server 2000

Hi there,

I Have an arraylist that holds both strings and integers and I was wondering what was the simplest way to export selected elements from it to a SQL Server 2000 table?
May 25 '07 #1
9 1360
Plater
7,872 Expert 4TB
Loop through it?
You are going to need to be more specific then that. We need details :-)
May 25 '07 #2
Hi,

Ok, so I loop through it, using IEnumerator? Then shall I create a temporary datatable where the data will be sent to, just before being imported to the sql database?
May 25 '07 #3
Plater
7,872 Expert 4TB
ArrayLists can be accesed with []
Expand|Select|Wrap|Line Numbers
  1. //if you have mixed content
  2. for (int i=0;i<myarraylist.Count;i++)
  3. {
  4.    // do something with myarraylist[i]
  5.    if (myarraylist[i].GetType()==typeof(string))
  6.    {
  7.       string myval=(string)myarraylist[i]);
  8.    }
  9.    if (myarraylist[i].GetType()==typeof(int))
  10.    {
  11.       int myval=(int)myarraylist[i]);
  12.    }
  13. }
  14.  
  15. //if content is all of same type
  16. foreach(string mystring in myarraylist)
  17. {
  18.    // do something with mystring
  19. }
  20.  
May 25 '07 #4
Thanks a lot Plater!
I never thought of doing it that way.

What about the export bit? Is using a temporary datatable the most effective solution?
May 25 '07 #5
Plater
7,872 Expert 4TB
use SQL's INSERT and UPDATE to stick them into a table.

Check How to use a Database in your program for more information on databasing
May 25 '07 #6
Thanks for the link.

In the exemple given the values are included in the code:

Expand|Select|Wrap|Line Numbers
  1. sqlCom.Connection = dbCon
  2. sqlcom.CommandType = CommandType.Text
  3. sqlCom.CommandText = "INSERT INTO CLIENT_TABLE(cID, cAddress, cPhoneNumber)" _
  4. " VALUES(@cID,@cAddress,@cPhoneNumber)"
  5. sqlCom.Parameters.Add("@cID", SqlDbType.Int).Value = "1234567"
  6. sqlCom.Parmaeters.Add("@cAddress", SqlDbType.VarChar).Value = "123 Hypoth. Street..."
  7. sqlCom.Parameters.Add("@cPhoneNumber",SqlDbType.VarChar.Value="1-800-999-99999"
What is the cleanest way to use values from an arrayList directly?
May 25 '07 #7
Plater
7,872 Expert 4TB
Just use the values in place of the hardcoded ones?
Expand|Select|Wrap|Line Numbers
  1. sqlCom.Connection = dbCon
  2. sqlcom.CommandType = CommandType.Text
  3. sqlCom.CommandText = "INSERT INTO CLIENT_TABLE(cID, cAddress)" _
  4. " VALUES(@cID,@cAddress)"
  5. sqlCom.Parameters.Add("@cID", SqlDbType.Int).Value = myarraylist[i].ToString(); 
  6. sqlCom.Parmaeters.Add("@cAddress", SqlDbType.VarChar).Value = myarraylist[i+1].ToString();
  7.  
  8.  
May 25 '07 #8
Thanks a lot Plater, you solved my problem from A to Z, I appreciate it.
Have a good weekend.

God Bless.
May 25 '07 #9
peruse the System.Data.DataSet
and System.Data.SqlClient.SqlDataAdapter classes as well.
May 26 '07 #10

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

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
7
by: GTi | last post by:
I have a listview that with selected items. But I want to "reselect" items after a refresh. Each items have a uniqe value in the Tag object. After a refresh some new items may be added or removed...
2
by: Stephen Miller | last post by:
When I dynamically populate a HtmlSelect combo box, the Value property consistently fails to return the item selected, defaulting instead to the first item in the list. For example: Protected...
1
by: Empire City | last post by:
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a ListItem in the cell. The display part works fine. I...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
9
by: ajos | last post by:
Hello friends, After thinking about this for sometime, i decided to post this in the java forum. Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo...
3
by: jrnowlan | last post by:
I have the following code that takes form data from a picklist and uses the input values to query an access database. Currently everything works, but it writes the results to the same page when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.